在我的jquery中,我想从查询mysql中获取数组中的值数组。但是当我在控制台中检查时,我得到了数组中的对象。我将使用我的查询mysql中的示例数据和数据编写示例代码。
var locationsSample = [
[-6.175656, 106.812630,'ONSHORE',1,'id1'],
[-6.192848, 106.822027,'OFFSHORE',1,'id2'],
[-6.164234, 106.328973,'FABRICATION SHOP',1,'id3'],
[-0.594009, 100.735315,'SUMATERA',0,'id4'],
[5.168138, 97.124416,'SUMATERA ACEH',1,'id5']
];
console.log(locationsSample);
from console => Array [ Array[5], Array[5], Array[5], Array[5], Array[5] ] this is a true.
这是我的PHP代码:
filename:jsonarray.php
$qry="SELECT latitude,longitude,project_name,status,id_tbl_project_map FROM tbl_project_map";
$res = mysql_query($qry) or die('Query failed: ' . mysql_error());
$rows= array();
while($data=mysql_fetch_assoc($res))
{
$rows[]=$data;
}
print json_encode($rows);
和jquery调用文件jsonarray.php:
locations = new Array();
$.ajax({
url:"jsonarray.php?id=2",
type:"POST",
dataType:"json",
success:function(retqry){
locations = retqry;
console.log(locations);
from console => Array [ Object, Object, Object, Object, Object ] this is a false. why i'm get a Object not Array[5] from example code in top
}
});
请帮助,谢谢。
答案 0 :(得分:0)
尝试这种方式存档您的要求,
TypeID TypeTitle
-----------------
1 A
2 B
3 C
请注意,此代码未经过测试,您可能需要根据需要更改代码。希望这对你有用!
问候!