what is the json data format ie understands?

2019-08-10 03:53发布

问题:

I am calling a php script to get the data using ajax. It works without any problems on chrome and other browsers but on IE (of course) it does not work.

My data format is as follows:

[1234000000000,56]

this is the script I am trying to call to get the abobe value:

$.ajax({

        url: 'get_cpu.php', 
        success: function(data) {
          var myObj = JSON.parse(data); 
                        alert(obj);

I tried outputing this file in many different formats to make IE happpy without any luck. How can I format this data in json so that ie understands? I really appreciate any insight?

Best regards,

回答1:

Old versions of IE don't have the built-in JSON object. Therefore, JSON.parse doesn't exist. It has nothing to do with your JSON format.

Since you are using jQuery, you don't need to worry JSON parsing; it will take care of it. In your $.ajax call, add dataType: 'json'. This will make jQuery parse it for you automatically.

$.ajax({
    url: 'get_cpu.php',
    dataType: 'json',
    success: function(data) {
        console.log(data);
    }
});

If you weren't using jQuery, you would have to use a JSON replacement library, like json3.js.



回答2:

Please refer to this page and wikipedia. All of code there runs in all browsers.