Chrome,Safari - 未捕获的类型错误:无法读取 null 的属性“状态”

Chrome,Safari - Uncaught TypeError: Cannot read property 'status' of null

本文关键字:读取 null 属性 状态 错误 Safari 类型 Chrome      更新时间:2023-09-26

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

它在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 框架。

请提出任何解决方案。

尝试使用

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

if(responseObject.hasOwnProperty('status'))

if('status' in responseObject)

学分来自:JavaScript isset() 等效