我有一个问题,将数据从一个JQuery ajax调用传回到调用位置。在考虑中的代码如下:将jQuery ajax值传递回调用JavaScript函数
jQuery("#button").click(function()
{
for(var i = 0;i < data.length; i++)
{
result = updateUser(data[i]); //result is not populated..
alert(result); //prints 'undefined'
}
});
function updateUser(user_id)
{
jQuery.ajax({
url:"https://stackoverflow.com/users/update/"+user_id,
type:"GET",
async: false,
success: (function(data){
//if I alert "data" here it shows up correctly
//but if i try to return it like below
//it does not get passed correctly
return data;
})
});
任何指针是非常感谢
[jQuery ajax请求内部函数的可能重复:如何返回我得到的值?](http://stackoverflow.com/questions/3619888/jquery-ajax-request-inside-a-function-how-返回值我得到) – bfavaretto