JSON.parse not working in Chrome

I have a strange problem that I cannot understand. I'm too simple to be wrong. The problem is present in Chrome 12.0.742.91, but it works fine in IE8 8.0.6001.19048.

This is my AJAX callback function, and this is an instance of XMLHttpRequest.

 // default AJAX callback handler function Handler() { if (this.readyState == 4 && this.status == 200) { // alert(">>"+this.responseText+"<<"); var Response = this.responseText; // Response = '{"Status":0,"Data":"My Data"}'; document.getElementById("debug").innerHTML = Response; var Ajax = JSON.parse(Response); document.getElementById("Stat1").innerHTML = Ajax.Status+"<br />"+Ajax.Data; } 

The AJAX server sends {"Status":0,"Data":"Server Data"} , and it is displayed in exactly the same way in the debug element; Server Data

 header('Content-type: application/json'); print '{"Status":0,"Data":"Server Data"}'; 

The warning (...) displays >>{"Status":0,"Data":"Server Data"}<< , additional spaces before or after the JSON data.

But when parsing with JSON.parse (), I get a javascript error: Invalid token.

However, if I hardcode the same line (activates the marked line), JSON.parse () works without errors and displays the data ( My Data ) in the stat1 element.

In IE8, Server Data runs flawlessly ...

Have I really forgotten something fundamental or is there a known issue with Chrome?

[EDIT] Upon request, you will find an instance of XMLHTTPRequest here:

 // Create the XMLHttpRequest object function GetHTTPRequestObject() { var httpRequest = null; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari httpRequest = new XMLHttpRequest(); } else {// code for IE6, IE5 httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } return httpRequest; } 
+4
source share
1 answer

This will open the answer to this question , this is due to the Unicode specification.

+3
source

All Articles