title: JQuery Ajax Get different type of variable in javascript compare with PHP
body: <p>In my php code, I echo object type of variable. However, in JQuery ajax success return data is in the form of String data. I am using JSON.parse(data) to parse data into JSON form. But I can't do it due to the format of return string data. May I know how can I return JSON object in php and at the same the in my JQuery $ajax function will get the JSON object also and not string. The following is my code.</p>
  
  <p>Javascript:</p>
  
  <pre><code>$(document).ready(function callAjax(){
          $.ajax({
              type: "GET",
              url: "php/test.php",
              cache: false,
              success: function(data){
                  console.log( data);
                   interval = setTimeout(callAjax, 1000);  
              }
          })
  });
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php
      require('test2.php');
  
     $messages = get_msg();
      if (is_array($messages) || is_object($messages)){
          foreach($messages as $message){
        $array = array('chat_id' =&gt; $message['chat_id'], 
                      'sender_name' =&gt; $message['sender_name'],
                      'chat_body' =&gt; $message['chat_body'], 
                      'chat_time' =&gt; $message['chat_time']);
        $object = (object) $array;
              echo json_encode(gettype ($object));
          }
      }else{
          echo "Nothing";
      }
  ?&gt;
  </code></pre>