好的,所以這是一個奇怪的。我的Ajax調用似乎同時調用成功和失敗。當我發送我的Ajax調用時,它會發送到數據庫,但也會拋出錯誤消息。所以Ajax調用正在工作 - 只是帶有錯誤消息。當我使用Fiddler檢查問題時,請求發佈爲200(成功)。Ajax調用成功和失敗
的代碼非常簡單:
var myDataObject = new Object();
myDataObject.one = $('#SomeTextBoxId').val;
myDataObject.two = $('#SomeOtherTextBoxId').val
// NOTE: AJAX is calling success and fail
SendAjax("/ServiceHandlers/SomeHandler?HandlerName", myDataObject, function() { alert("SUCCESS!");}, function() {alert("FAILURE?");});
這裏是SendAjax
功能:
function SendAjax(postUrl, postData, successFunction, failureFunction)
{
/*
postUrl: The URL to which the request will be posted
postData: The JSON encoded input to be posted to the postUrl
successFunction: The function to be executed on a successful post
failureFunction: The function to be executed on a failed post
*/
// Stringify the postData
postData = JSON.stringify(postData);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: postUrl,
data: postData,
success: function (data, status, xhr)
{
successFunction(data, status, xhr);
},
error: function (xhr, status, error)
{
failureFunction(xhr, status, error);
}
});
}
有什麼建議?
編輯 - 修正了Ajax調用函數,仍然沒有運氣。
您的代碼是否讀取了'function {alert(「SUCCESS!」);}'或'function(){alert(「SUCCESS!」);}'?這些括號非常重要。 – Gareth 2013-05-10 14:07:25
順便說一下,這是什麼Ajax框架?看起來不錯和簡單。 – Goodwine 2013-05-10 14:10:56
@Gareth對不起,它讀取函數(){alert(「SUCCESS!」);} – 2013-05-10 14:13:26