【发布时间】:2015-05-25 00:12:55
【问题描述】:
在deferred.then 回调中返回数据时如何传递多个参数?
var data = {
json: JSON.stringify({
text: 'some text',
array: [1, 2, 'three'],
object: {
par1: 'another text',
par2: [3, 2, 'one'],
par3: {}
}
}),
delay: 3
};
$.ajax({
url:'/echo/json/',
data: data,
type: 'POST'
}).then(function(response, statusText, jqXhr){
response.text = 'foo';
// how to return the rest of the arguments correctly?
return response;
}).done(function(response, statusText, jqXhr){
console.log(response); // <- altered response
console.log(statusText); // <- how to pass it along?
console.log(jqXhr); // <- how to pass it along?
});
【问题讨论】:
-
不返回更改后的数据,而是直接调用 next 函数,并使用修改后的参数。
-
@Barmar 返回一个对象仍然会使
done回调中的参数 2 和参数 3 未定义,对吗?我想知道是否有办法在then回调中设置它们
标签: javascript jquery promise