【问题标题】:Chrome,Safari - Uncaught TypeError: Cannot read property 'status' of nullChrome,Safari - 未捕获的类型错误:无法读取 null 的属性“状态”
【发布时间】:2013-10-01 12:55:19
【问题描述】:

我通过每半分钟发送一次请求来更新我的页面上的一些帖子,然后在页面上显示更新的帖子。

它在 FireFox 中正常工作,但在 Chrome 和 Safari 中,显示错误“无法读取 null 的属性'状态'”。以下是我发送请求并在成功时显示结果的 JavaScript 代码。

var updatePost = function() {

    var lastid = document.getElementById('lastTopic').value;

    en4.core.request.send(new Request.JSON({
      url : en4.core.baseUrl + 'group/topic/topic-update',
      data : {
        format : 'json',        
        lastid : lastid,
        topic_id : '<?php echo $this->topic->getIdentity(); ?>',
        group_id : '<?php echo $this->group->getIdentity(); ?>',
      },
      onRequest:function()
          {

          },
      onSuccess : function(responseObject) {
        if(responseObject.status) {

            // Remove old last topic id
            $('lastTopic').remove();

            //Add notification at top of list
            $('topicUpdateNotify').innerHTML = "<a href='javascript:void(0);' onclick='scrollToPost("+responseObject.newLastId+");'>New Post update is available - click this to show it. </a>";

            // Append li to list with content
            var ul = document.getElementById("group_discussions_thread");
            var newLI = document.createElement("LI");
            newLI.innerHTML = responseObject.body;
            ul.appendChild(newLI);                  
        }
      }
    }));
    };

请求成功后,我使用if(responseObject.status) {} 检查了状态。它在 FF 中正常工作,但在 Chrome 和 Safari 中没有显示结果。

我正在使用 zend 框架。

请提出任何解决方案。

【问题讨论】:

    标签: javascript ajax zend-framework


    【解决方案1】:

    尝试使用

    if(typeof responseObject.status != 'undefined')
    

    if(responseObject.hasOwnProperty('status'))
    

    if('status' in responseObject)
    

    学分来自: JavaScript isset() equivalent

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-18
      • 2016-09-13
      • 2022-01-01
      • 1970-01-01
      • 2022-01-19
      • 2021-12-01
      • 2022-07-02
      相关资源
      最近更新 更多