[英]passing data from ajax function to another after ajax finishes
试图从ajax调用将数据传递给jvectormap
,我具有when
函数,因此代码在ajax
完成加载后运行
我的问题是地图为空,并且出现错误
未捕获的ReferenceError:未定义postdata
这是我目前拥有的代码
$(document).ready(function() {
function ajax1() {
return $.ajax({
url: "src/data.php?form_action=call-map",
type: "GET",
data: postdata,
dataType: "text", // the type of data that you're expecting back from the server
error: function(jqXHR, textStatus, errorThrown) {
$().toastmessage("showErrorToast",
"AJAX call failed: "+textStatus+" "+errorThrown);
},
success: function(data) {
console.log(data);
//return false;
}
});
}
$.when(ajax1()).done(function(a1){
$('#world-map').vectorMap({
map: 'world_mill_en',
backgroundColor: "transparent",
regionStyle: {
initial: {
fill: '#e4e4e4',
"fill-opacity": 0.9,
stroke: 'none',
"stroke-width": 0,
"stroke-opacity": 0
}
},
series: {
regions: [{
values: a1,
scale: ["#005aad", "#001d38"],
normalizeFunction: 'polynomial'
}]
},
onRegionTipShow: function(e, el, code){
el.html(el.html()+ '<br>Time Used: '+mapData[code]);
}
});
});
});
这是从ajax调用返回到php脚本的返回数据
{"AF" : 10, "AX" : 22, "AL" : 5, "DZ" : 0, "AS" : 41, "AD" : 74, "AO" : 30}
的console.log(数据); 显示我需要传递给jvectormap
所有数据。
您的postdata
变量未初始化(在您在此处发布的代码段中!)更改此命令:
url: "src/data.php?form_action=call-map",
type: "GET",
data: postdata,
dataType: "text", // the type
对此:
url: "src/data.php",
type: "GET",
data: "form_action=call-map",
dataType: "text", // the type
但是,如果变量“ postdata”对您有意义,请向我们展示您对其重视的地方。
我可以通过使用以下命令转换字符串中的数据类型来解决此问题:
var a1 = JSON.parse(a1);
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.