(抱歉,我發佈了一個非常類似的問題早,但它看起來像我原來的問題是有點關閉)修改陣列格式
這裏是我的代碼:
$.ajax({
url: 'receive-country.php', //the script to call to get data
dataType: 'json', //data format
success: function(data) //on recieve of reply
{
var inputArray = data;
alert(data);
var test_data = {"af":16.63,"al":11.58,"dz":158.97};
jQuery('#vmap').vectorMap({
map: 'world_en',
backgroundColor: null,
color: '#ffffff',
hoverColor: '#eeeeee',
hoverOpacity: null,
selectedColor: '#dddddd',
values: test_data,
enableZoom: true,
showTooltip: true,
scaleColors: ['#C8EEFF', '#006491'],
normalizeFunction: 'polynomial'
});
}
});
我通過Ajax接收一些data
,我想要顯示在我的jQuery地圖#vmap
。我創建了一些test_data
,可以與地圖一起使用,但我似乎無法使用與test_data
相同的格式獲得data
。
我不知道到底是什麼陣列格式data
是,但是當我提醒它,它出來的:
US,7,US,9,US,10
我怎樣才能更改格式?
這裏是PHP頁面發送JSON數據:
$country_result = mysql_query("SELECT * FROM happiness ORDER BY id ASC");
$country_array = array();
while($row = mysql_fetch_array($country_result)) {
$country_array[] = array($row[4], $row[2]);
}
echo json_encode($country_array);
謝謝!
編輯:
這裏是控制檯日誌的屏幕截圖。我不確定如何準確讀取它。
使用'console.log'而不是alert,您將看到數據類型。 – 2013-03-24 22:10:31
真棒,我會檢查。 – 2013-03-24 22:12:45