如何将值传递给jQuery Ajax成功处理程序 [英] how to pass a value to jQuery Ajax success-handler
本文介绍了如何将值传递给jQuery Ajax成功处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在jQuery中提供以下Ajax调用:
Give the following Ajax call in jQuery:
{
.
.
.
,
getSomeData: function(args, myUrl, foo) {
$.ajax( {
type: "GET",
url: myUrl,
data: args,
async: true,
dataType: 'json',
success: myHandler
});
},
myHandler: function (data, textStatus, oHTTP, foo){ ... }
};
可以将值foo
附加到传递给成功处理程序myHandler
的参数上吗?是否有任何方法可以将值传递给GET上的服务器,并使该值以往返方式返回给客户端,并再次出现在成功处理程序的参数列表中?我无法更改data
中返回的内容的结构.
Can value foo
be somehow appended to the arguments that are passed to success-handler myHandler
? Is there any way to pass a value up to the server on the GET, and have that value come back to the client in a round-trip, reappearing in the success-handler's arguments list? I cannot change the structure of what is returned in data
.
推荐答案
If you declare myHandler
within the request, you can use a closure.
getSomeData: function(args, myUrl, foo) {
$.ajax( {
type: "GET",
url: myUrl,
data: args,
async: true,
dataType: 'json',
success: function (data, textStatus, oHTTP){ ... }
});
},
这样,在success
回调中可以使用foo
.
this way, foo
will be available to you inside the success
callback.
这篇关于如何将值传递给jQuery Ajax成功处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文