title: Ajax - returned json object is null in ie
body: <p>Hi I have a javascript code that connects to a php script via ajax. This php script returns an array. In the success function of the ajax call, I use the returned array to display information to the user. This all works fine in all the browsers I have tried except Internet Explorer. I get the following error:</p>
  
  <pre><code>Unable to get property '0' of undefined or null reference
  </code></pre>
  
  <p>'0' is the index of the first element in the array. Here is the code:</p>
  
  <p>JS</p>
  
  <pre><code>$.ajax({
      type: "POST",
      url: "/add.php",
      data: 'id=' + itemid,
      dataType: "json",
      success: function (data) {
          document.getElementById("name").innerHTML = data[0];
          document.getElementById("desc").innerHTML = data[1];
          document.getElementById("price").innerHTML = data[2];
      },
      error: function (xhr, ajaxOptions, thrownError) {
          alert(xhr.status);
          alert(thrownError);
      }
  });
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>$output = array();
  $output[0] = $itemname;
  $output[1] = $itemdescription;
  $output[2] = $itemprice;
  echo json_encode($output);
  exit();
  </code></pre>
  
  <p>I tried <code>console.log(data)</code> in the success function and in Internet Explorer it returns null whereas other browsers it returns the array. Does anyone know what is wrong here?</p>
  
  <p>The error code on the console in IE is SCRIPT5007. Upon searching this, this means:</p>
  
  <pre><code>You attempted to invoke the Object.prototype.toString or Object.prototype.valueOf method on an object of a type other than Object. The object of this type of invocation must be of type Object.
  </code></pre>
  
  <p>Link: <a href="http://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&amp;l=EN-GB&amp;k=k(VS.WebClient.Help.SCRIPT5007)" rel="nofollow">http://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&amp;l=EN-GB&amp;k=k(VS.WebClient.Help.SCRIPT5007)</a></p>