怎么会
ajaxFunction().done(function(p){
console.log(p);
});
按照ajaxFunction中dataType
中指定的HTML格式返回数据,但是
var data = ajaxFunction().done(function(p){
console.log(data)
//returns what appears to be the entire deferred object
//to see the returned HTML string, I have to do console.log(data.responseText);
});
一旦我将该对象存储在数据中,该对象的实际应用是什么?我可以用它做进一步的事情吗?或者它不打算这样使用吗?
最佳答案
您的变量data
是ajaxFunction()
返回的promise。
通过引用它,您可以添加更多 .done
回调以及 .fail
回调,如果您的 ajaxFunction()<,后者会很方便
没有内置的错误处理。
在您的回调函数中,直接访问该变量将是,嗯,不寻常 - 您应该使用它的p
。
关于javascript - 将返回的ajax变量设置为done()给了我一个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14635399/