商店阿贾克斯结果jQuery的变量 [英] Store ajax result in jQuery variable
本文介绍了商店阿贾克斯结果jQuery的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始使用jQuery和AJAX来从数据库中的数据,但我不能找出如何我可以节省$。获得()结果为变量的回调函数外。
I started using jQuery and ajax to get data from database, but i cant find out how i can save result of $.get() into variable outside callback function.
这是我的jQuery脚本:
This is my jquery script:
var result="";
$.get("test.php", function(data){ result=data; });
alert(result);
这是test.php的脚本:
This is test.php script:
echo "Hello, World";
我每次运行此脚本则会发出警报。
Every time i run this script it alerts "".
推荐答案
试试这个:
var result = "";
$.get("test.php", function (data) {
SomeFunction(data);
});
function SomeFunction(data) {
result = data;
alert(result);
}
这篇关于商店阿贾克斯结果jQuery的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文