问题:未调用 Ajax 回调方法 (get)。
$("input[id*='chkSelect']:checked").each(function (i, v) {
$.get("AjaxCallHandler.aspx?tc_id=" + tc_id, function (response) {
if (response != null && response != '') {
//update some labels with the return type
}
}
});
});
服务器端:
protected void Page_Load(object sender, EventArgs e)
{
var str = Request.QueryString["tc_id"] != null ? Request.QueryString["tc_id"] as string : string.Empty;
int tc_id;
if (int.TryParse(str, out tc_id))
{
string response = string.Empty;
if (tc_id %2 == 0)
{
response = "sessionId1,Success";
}
else
{
response = "sessionId2,Failure";
}
Response.Clear(); //clears the existing HTML
Response.ContentType = "text/plain"; //change content type
Response.Write(response);
Response.End(); //end
}
}
PS在我将不同的母版页应用于页面之前,代码工作得非常好。我尝试了不同的 get 方法重载来检查错误,但这也无济于事。
function (response, textStatus, jqXHR) {
if (response != null && response != '') {
//update some labels with the return type
}
}
}
正如凯文所建议的那样,我尝试在$.get中添加 failHandler
$.get("AjaxCallHandler.aspx?tc_id=" + tc_id,
function (response, textStatus, jqXHR) {
if (response != null && response != '') {
//update some labels with the return type
}
}
}).fail(failHandler);
function failHandler(data, textStatus, jqXHR) {
console.log(data);
console.log(textStatus);
console.log(jqXHR);
};
这是输出 文本状态: parsererror jqXHR: SyntaxError
我从服务器返回的只是"sessionId1,Success"
不知道出了什么问题?