Perfect Coders
Perfect Coders

Reputation: 57

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

I am updating some post on my page by sending request on every half minute and then displaying updated posts on page.

It is working properly in FireFox but in Chrome and Safari, showing error of "Cannot read property 'status' of null". Following is my JavaScript code to send request and displaying result on success.

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);                  
        }
      }
    }));
    };

On success of request I have checked for status using if(responseObject.status) {}. It is working in FF properly but not showing result in Chrome and Safari.

I am working in zend framework.

Please suggest any solution.

Upvotes: 1

Views: 4367

Answers (1)

Getu.ch
Getu.ch

Reputation: 94

try to use

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

or

if(responseObject.hasOwnProperty('status'))

or

if('status' in responseObject)

Credits from: JavaScript isset() equivalent

Upvotes: 2

Related Questions