【发布时间】:2013-09-14 18:32:38
【问题描述】:
谁能告诉我为什么我在这个 jQuery 中的成功回调没有被调用?
$(document).ready(function () {
var queueid = $('#hidqueueid').val();
var queuemax = $('#hidqueuemax').val();
var queuenext = $('#hidqueuenext').val();
var sid = $('#hidsid').val();
var acc = $('#hidacc').val();
var key = getCookie('account_key');
var processNext = function() {
var url = "functions.aspx?sid=" + sid + "&acc=" + acc + "&func=processqueue&id=" + queueid + "&next=" + queuenext + '&key=' + key;
showProgress();
$.post(url, function (data) {
alert(data); // <== never happens :(
var result = $(data).attr('result');
if (result == 'ok') {
queuenext = $(data).attr('next');
if (queuenext > 0) {
$('#hidqueuenext').val(queuenext);
processNext();
} else {
var newurl = 'Data.aspx?sid=' + sid + '&acc=' + acc;
location.href = newurl;
}
}
}, function() {
// error
alert('Oops!');
});
};
var showProgress = function() {
var output = "<div>" + queuenext + " of " + queuemax + "</div>";
$('#divprogress').html(output);
};
processNext();
});
返回结果的 C# 工作正常,如下所示:
string xml = new Queue(sid, acc, queueId).ProcessItem(queueNext, key);
Response.ClearContent();
Response.ContentType = "text/xml";
Response.Write(xml);
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
当我调试 C# 时,XML 看起来很好
感谢您的帮助!欢迎所有建议。
【问题讨论】:
-
什么 HTTP 状态通过网络传输?
-
我不知道。我怎样才能知道?我会尝试谷歌搜索它
-
使用调试工具,如Fioddler
-
$.post 只接受成功回调,不接受错误回调(与返回的promise接口不同)检查DOC。我认为您的第一个回调被忽略(应该是数据对象),第二个被用作成功回调
-
直接编写内容可能不是最佳选择。考虑使用
JSON作为操作方法的结果。