[問題] Javascript json to array 轉換
var test;
$.post("query.php",{id:id})
.done(function(data){
test = $.parseJSON(data);});
console.log(test);
data是有撈出資料的
但是test一直顯示是undefined
這個問題是什麼呢!?
data內容:
[{"0":"120.95","rest_lon":"120.95","1":"24.8","rest_lat":"24.8",
"2":"\u65b0\u7af9\u5e02\u5927\u5b78\u8def1001\u865f",
"rest_address":"\u65b0\u7af9\u5e02\u5927\u5b78\u8def1001\u865f",
"3":"03-3369880","rest_tel":"03-3369880"},
{"0":"120.96","rest_lon":"120.96","1":"24.81","rest_lat":"24.81",
"2":"\u65b0\u7af9\u7e23\u5927\u5b78\u8def1\u865f",
"rest_address":"\u65b0\u7af9\u7e23\u5927\u5b78\u8def1\u865f",
"3":"03-2571864","rest_tel":"03-2571864"}]
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.134.94
※ 文章網址: https://www.ptt.cc/bbs/Web_Design/M.1422538725.A.37D.html
→
01/29 21:58, , 1F
01/29 21:58, 1F
推
01/29 22:08, , 2F
01/29 22:08, 2F
→
01/29 22:09, , 3F
01/29 22:09, 3F
→
01/29 22:11, , 4F
01/29 22:11, 4F
var test;
$.post("query.php",{id: id})
.done(function(data){
test = data;});
alert(test);
還是一樣test是undefined
主要就是想要把撈出來的資料可以到括號外面使用
※ 編輯: tony5566 (140.113.134.94), 01/29/2015 22:27:34
推
01/29 22:33, , 5F
01/29 22:33, 5F
→
01/29 22:46, , 6F
01/29 22:46, 6F
推
01/29 23:15, , 7F
01/29 23:15, 7F
→
01/29 23:16, , 8F
01/29 23:16, 8F
推
01/29 23:36, , 9F
01/29 23:36, 9F
→
01/30 00:07, , 10F
01/30 00:07, 10F