好的,所以这是一个奇怪的。我的 Ajax 调用似乎同时调用了成功和失败。当我发送我的 Ajax 调用时,它会发布到数据库,但也会抛出错误消息。因此,Ajax 调用正在工作——只是带有一条错误消息。当我检查 Fiddler 的问题时,请求发布为 200(成功)。
代码非常简单:
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 调用中的固定功能,仍然没有运气。