Javascript 加载ajax数据时出现jVectorMap问题
我试图在使用jvectormap插件创建的地图中显示来自访问者的数据 这让我抓狂,我无法通过ajax加载数据,如果我手动放置数据,它就会工作 到目前为止,我有: map.phpJavascript 加载ajax数据时出现jVectorMap问题,javascript,php,jquery,ajax,jvectormap,Javascript,Php,Jquery,Ajax,Jvectormap,我试图在使用jvectormap插件创建的地图中显示来自访问者的数据 这让我抓狂,我无法通过ajax加载数据,如果我手动放置数据,它就会工作 到目前为止,我有: map.php $datos = array(); $link->set_charset("utf8"); $sql = $link->query("SELECT SUM(ID) as visitors, state FROM visitors WHERE state != '' GROUP BY state"); whil
$datos = array();
$link->set_charset("utf8");
$sql = $link->query("SELECT SUM(ID) as visitors, state FROM visitors WHERE state != '' GROUP BY state");
while($row = $sql->fetch_row()){
$ss = $link->query("SELECT * FROM states WHERE state = '".$row[1]."'");
$rr = $ss->fetch_row();
$datos[] = array("ccode" => $rr[2], "visits" => $row[0]);
}
$data = array("countries" => $datos);
echo json_encode($data,JSON_NUMERIC_CHECK);
这将返回以下数据:
{"countries":[{"ccode":"VE-A","visits":81},{"ccode":"VE-L","visits":24}]}
现在,加载地图的函数为:
function cargaMapa(){
//jvectormap data
$.post("ajax/map.php",{},function(mapa){
var dataC = eval(mapa);
//var dataC = {"countries":[{"ccode":"VE-A","visits":81},{"ccode":"VE-L","visits":24}]};
var countryData = [];
//for each country, set the code and value
$.each(dataC.countries, function() {
countryData[this.ccode] = this.visits;
console.log("Estado: "+this.ccode+" Visitas: "+this.visits);
});
//World map by jvectormap
$('#world-map').vectorMap({
map: 've_mill_en',
backgroundColor: "#fff",
regionStyle: {
initial: {
fill: '#e4e4e4',
"fill-opacity": 1,
stroke: 'none',
"stroke-width": 0,
"stroke-opacity": 1
}
},
series: {
regions: [{
values: countryData,
scale: ["#3c8dbc", "#2D79A6"], //['#3E5E6B', '#A6BAC2'],
normalizeFunction: 'polynomial'
}]
},
onRegionLabelShow: function(e, el, code) {
//search through dataC to find the selected country by it's code
var country = $.grep(dataC.countries, function(obj, index) {
return obj.ccode == code;
})[0]; //snag the first one
//only if selected country was found in dataC
if (country != undefined) {
el.html(el.html() + ': ' + country.ccode + country.visits + ' visitas');
}
}
});
});
}
正如您在函数中看到的,我有var dataC,如果我在其中加载来自map.php的数组,它会给我未捕获的语法错误:意外标记:
,但是如果将map.php的结果复制并粘贴到var dataC中,它的效果相当好
我怎样才能解决这个问题
谢谢你的帮助
谢谢我明白了,只是把
$改成了$的post
。getJSON
魔术开始了