【发布时间】:2014-05-27 12:01:26
【问题描述】:
我必须使用 ajax 和 httphandler 将数据从 SQL 填充到 jvectormap。
我可以让 json 填充 jvectormap,但我不知道如何传递从 ajax 获得的数据
$.ajax({
url: 'CountryRegistrations.ashx',
type: 'POST',
success: function (data) {
var dataC = data;
},
error: function (data) {
alert("Error");
}
});
var countryData = [];
//for each country, set the code and value
$.each(dataC.countries, function () {
countryData[this.Country] = this.Count;
});
$( function () {
//World map by jvectormap
$('#world-map').vectorMap({
map: 'world_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) {
var country = $.grep(dataC.countries, function (obj, index) {
return obj.Country == code;
})[0];
if (country != undefined) {
el.html(el.html() + ': ' + country.Count + ' new visitors');
}
}
});
})
我想将 dataC 从 ajax 传递给 var CountryData,然后传递给 jvectormap 函数。
我得到的数据是json格式的
"countries":[{"Country":"AE","Count":5},{"Country":"CH","Count":2},{"Country":"IN","Count":3},{"Country":"PK","Count":3},{"Country":"US","Count":2}]
【问题讨论】:
标签: c# javascript jquery ajax