$(document).ready(function() {
function doAjax(time_from, time_to){
var dataRsp;
$.ajax({
url: "/query/"+time_from+"/"+time_to,
type: "GET",
dataType: "json",
success: function(data){ dataRsp = data; },
});
alert(JSON.stringify(dataRsp));
};
doAjax(0,0);
}
以上是我的代码片段,我需要存储数据输入一个全局变量dataRsp Ajax响应,但我没能干这事我非常有变量混淆JS和jQuery中的范围。非常感谢。失败在JQuery中的AJAX功能改变一个全局变量
你没有忘记去改变它,它只是*** ***异步! – adeneo
[如何从AJAX调用返回响应?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) – adeneo