好的,所以这是一个奇怪的。我的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