(这里是AJAX菜鸟),我试图访问AJAX对象的属性,但是每次我尝试调用它们时,都会遇到undefined
错误。
我可以调用函数done(),fail()等,但是只能在返回的对象上调用,而不能在AJAX调用本身期间调用。 (这样做的结果没有任何意义)
我有以下电话:
return $.ajax({
type: "POST",
contentType: "application/json",
url: url,
data: jsonData,
headers: {
"Header1": data1,
"Header2": data2
}
});
输出为:
{readyState: 1, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
abort: ƒ (a)
always: ƒ ()
catch: ƒ (a)
done: ƒ ()
fail: ƒ ()
getAllResponseHeaders: ƒ ()
getResponseHeader: ƒ (a)
overrideMimeType: ƒ (a)
pipe: ƒ ()
progress: ƒ ()
promise: ƒ (a)
readyState: 4
responseJSON: {Message: "Authorization has been denied for this request."}
responseText: "{
↵ "Message": "Authorization has been denied for this request."
↵}"
setRequestHeader: ƒ (a,b)
state: ƒ ()
status: 401
statusCode: ƒ (a)
statusText: "Unauthorized"
then: ƒ (b,d,e)
__proto__: Object
很显然,我需要获取status
,依此类推,但是当我执行undefined
时,我就会得到ajaxReturned.status
。
例如,当我执行ajaxReturned.always
时,我得到ƒ (){return f.done(arguments).fail(arguments),this}
。
关于如何访问所需属性的任何建议?