$.ajax({
type: "POST",
url: "bla",
xhrFields: { responseType: "document" },
data: {},
success: function(arg,arg2,request){
console.log(request.responseXML)
}
})
为什么打印'undefined'?我该如何解决这个问题?
最佳答案
您是否期待 JSON 返回?当你尝试时会发生什么:
$.ajax({
type: "POST",
url: "bla",
dataType: 'xml',
}).done(function (response) {
console.log(response);
});
如果你看jQuery's documentation ,他们概述了如何:
The jQuery XMLHttpRequest (jqXHR) object returned by $.ajax() as of jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method.
因此,响应变量包含您需要的内容。要查看其结构,请执行 console.log()
并转到开发人员工具 (Chrome) 或 Firebug (Firefox) 中的“控制台”选项卡。
关于jquery - $.ajax 中的响应类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14416830/