jQuery将Ajax结果返回到外部变量 [英] jQuery return ajax result into outside variable
本文介绍了jQuery将Ajax结果返回到外部变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用ajax时遇到一些问题。
I have some problem using ajax.
如何将ajax的所有结果分配给外部变量?
How can I assign all result from ajax into outside variable ?
我用谷歌搜索并找到了这段代码。
I google it up and found this code..
var return_first = (function () {
var tmp = null;
$.ajax({
'async': false,
'type': "POST",
'global': false,
'dataType': 'html',
'url': "ajax.php?first",
'data': { 'request': "", 'target': arrange_url, 'method': method_target },
'success': function (data) {
tmp = data;
}
});
return tmp;
});
但对我不起作用。
任何人都可以知道该代码出了什么问题吗?
Can anybody tell what is wrong about that code ?
推荐答案
在
之后您缺少逗号了
You are missing a comma after
'data': { 'request': "", 'target': 'arrange_url', 'method': 'method_target' }
此外,如果您想 return_first
保存匿名函数的结果,您需要进行函数调用:
Also, if you want return_first
to hold the result of your anonymous function, you need to make a function call:
var return_first = function () {
var tmp = null;
$.ajax({
'async': false,
'type': "POST",
'global': false,
'dataType': 'html',
'url': "ajax.php?first",
'data': { 'request': "", 'target': 'arrange_url', 'method': 'method_target' },
'success': function (data) {
tmp = data;
}
});
return tmp;
}();
最后请注意()
。
这篇关于jQuery将Ajax结果返回到外部变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文