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

未捕获的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条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 有关c++的问题,利用相关知识
      • ¥15 求香农编码和解码的matlab代码
      • ¥20 ROS中的TEB局部规划问题
      • ¥20 关于#matlab#的问题:要求测出上面图片中所有同心圆的半径
      • ¥20 epanet软件运行问题
      • ¥15 Python 文件读取
      • ¥60 dpabi进行Alff计算时脑池有干扰信号
      • ¥15 利用kmeans或kshape聚类分析对归一化的无量纲时间-降雨序列进行聚类
      • ¥15 protel99.SE提示一下弹窗
      • ¥15 银河麒麟v10 执行.run失败如何解决