jQuery将Ajax结果返回到外部变量

编程入门 行业动态 更新时间:2024-10-28 14:31:02
本文介绍了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结果返回到外部变量

本文发布于:2023-10-12 17:45:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485422.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   jQuery   Ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!