doujue1246 2014-05-11 04:11
浏览 147
已采纳

未捕获的TypeError:无法读取null的属性“result”

Im trying to create an event by clicking a button which will submit three pieces of information that I provide. My PHP script is supposed to return a JSON encoded response of the success or failure of this event creation. An example of such a response is:

  {
    "result":true,
    "message":"Your event has been created"
  }

To return such a response, I have my PHP script doing the following:

  $answer = array ( "result" => true, "message" => "Your event has been created");
  return json_encode($answer);

When I click on the button to create the event on the web page, the developers console in Chrome displays the following message: Uncaught TypeError: Cannot read property 'result' of null. I've played around with the way I return that response but nothing has worked so far.

FYI, additional ajax code kicks in to determine what to do next once the response is received but based on the error, it seems that there is something wrong with the way I am returning the response.

Edit: Ajax code that will handle the returned response:

  // if that response is good
  if(response.result) {
        $('#event-create').dialog('close');
        $('#calendar').fullCalendar('refetchEvents');
  // otherwise error
  } else {
  $('#error-message').html(response.message).dialog('open');

EDIT 2: Echoing it out seemed to resolve the issue and there are no errors being thrown at the user. There is one more issue though left to be resolved that is listed in the developers console now though. Its the exact same error however it cannot read property 'length' of null. Unfortunately, I am not sure what its referring to in this case.

  • 写回答

2条回答 默认 最新

  • dongwu3747 2014-05-11 04:35
    关注

    return doesn't output anything in PHP, use echo

    $answer = array ( "result" => true, "message" => "Your event has been created");
    echo json_encode($answer);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记