我跟着this article添加web服務到我的office 365加載項。但是,當我執行發送請求的ajax腳本時,它總是以.fail語句結束。我看不到程序在控制器類或Global.asax或webApiConfig類中執行一行。使用ASP.NET web api添加一個web服務的辦公室加載項
這是我javasript代碼片段
function GetStyles(ooxml) {
var data = {
xml: ooxml
};
$.ajax({
url: 'api/GetStyles',
type: 'GET',
data: data,
contentType: 'application/json;charset=utf-8'
}).done(function (data) {
showNotification(data.Status, data.Message);
}).fail(function (status) {
showNotification('Error', 'Could not communicate with the server.');
}).always(function() {
// $('.disable-while-sending').prop('disabled', false);
});
}
這是控制器類
public class WriterController : ApiController
{
public class FeedbackRequest
{
public string xml;
}
public class FeedBackResponse
{
public string status;
public string message;
}
[HttpGet()]
public FeedBackResponse GetStyles(FeedbackRequest request)
{
try
{
return new FeedBackResponse
{
status = "success",
message = "success success",
};
}
catch (Exception e)
{
return new FeedBackResponse
{
status = "error",
message = "error error",
};
}
}
}
有人可以幫我解決這個問題呢?
在'.fail'中檢查'status'的值。它可能包含非常有用的信息。 –