0
我有简单的Ajax查询AJAX JSON返回undefined
$.ajax(
{
url:'ADMPANEL_POST.php',
type:'POST',
data:{'z':'1'},
dataType:'json',
success:function (result) {
alert("Data recieved: " + result.x);
$('#result').append(result.x);
}
});
在ADMPANEL_POST.php
我试图让Z = 1,并有相应的处理程序,并且我希望使用json_encode data_str回到阿贾克斯成功函数
if(isset($_POST['z']))
{
$init_x = 'test';
$data_str[] = array('x' => $init_x);
if($_POST['z']=='1') {
echo json_encode($data_str, true);
}
}
但是,我收到警报消息中data.x的未定义值。无法弄清楚是什么问题。谢谢。 P.S .:看到这个,但它没有帮助JSON returning as undefined
请尝试以下行: alert(“Data received:”+ result); $('#result')。append(result); – Amit 2013-03-23 18:42:13