The spec for the jQuery ajax.error
function仅指定第二个参数是:在JavaScript功能
error(XMLHttpRequest, textStatus, errorThrown)Function
我试图捕获错误并显示textStatus
,但我无法弄清楚如何,而不必仅指定textStatus
输入XMLHttpRequest
和errorThrown
的变量名称。我的代码目前看起来是这样的:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: hbAddressValidation.webServiceUrl,
data: this.jsonRequest,
dataType: "json",
timeout: 5,
success: function (msgd) {
//...
},
error: function (a,textStatus,b) {
$("#txtAjaxError").val("There was an error in the AJAX call: "
+ textStatus);
}
});
你可以在我的代码,我把变量a
和b
用作占位符在error
功能的第一和最后一个变量看。我知道在我的成功功能中,我只提供了一个参数,它工作正常,但在这种情况下,data
是第一个参数。在error
的情况下,textStatus
是第二个参数,但这是我想指定的唯一一个。这可能吗?
我同意“可怕的想法”部分:-) – Pointy 2010-05-12 20:32:20