我正在使用JQuery并通过Ajax调用从MySQL数据库读取值的PHP文件。(Wordpress)当值返回jQuery并将其输出到控制台时,这是获得的示例:a:1 :{i:0; i:90;}
我如何使用jQuery从此序列化数组访问值90,其中90将是一个不同的值,但始终位于同一位置?
$prod = $_POST['item'];
//$mod_prod = substr($prod, 0, strpos($prod, "|"));
//query to get data from the table
$query_Product = sprintf("select meta_value from wp_postmeta Where post_id = '".$prod."' and meta_key = '_upsell_ids'");
//execute query
$result_Product = $mysqli_Product->query($query_Product);
//loop through the returned data
$data_ListRD = array();
foreach ($result_Product as $row) {
$data_ListRD[] = $row;
}
//free memory associated with result
$result_Product->close();
//close connection
$mysqli_Product->close();
//print_r(json_encode($data_ListRD));
//now print the data
print json_encode($data_ListRD);
$ data_ListRD我认为是一个数组,如何将它反序列化?
您需要使用$ .parseJSON函数。尝试这样:
var data = {a:1:{i:0;i:90;}} //data that comes from AJAX.
var unserializedData = $.parseJSON(data);
console.log(unserializedData);