Javascript 未捕获类型错误:运行ajax php时无法读取未定义的属性“status”
我的回答一直得到未定义的回报 My index.php有一个触发以下代码的事件处理程序Javascript 未捕获类型错误:运行ajax php时无法读取未定义的属性“status”,javascript,php,ajax,Javascript,Php,Ajax,我的回答一直得到未定义的回报 My index.php有一个触发以下代码的事件处理程序 $.post("getData.php", onNewPost()); function onNewPost (response){ if (response.status == "OK") { console.log(response); } };//end new post 我的getdata.php如下所示 <?php $data = array("status"
$.post("getData.php", onNewPost());
function onNewPost (response){
if (response.status == "OK") {
console.log(response);
}
};//end new post
我的getdata.php如下所示
<?php
$data = array("status" => "OK");
将index.php更改为
$.post("getData.php", onNewPost);
function onNewPost (response){
// console.log(response);
response_parse = JSON.parse(response);
if (response_parse.status == "OK") {
console.log(response);
}
};//end new post
getdata.php
$data = array("status" => "OK");
die(json_encode($data));
在这里,首先在getdata.php中创建数组,并对该数据进行json_编码。
在脚本中解析返回的数据之后,这将把数据转换为JavaScript对象 post行应该是这样的$.postgetData.php,onNewPost;仍然返回undefined@dontay请更新问题中的代码。另外,PHP脚本中的$data如何成为响应?