GET AJAX - Json size issue on fast updates
I am using AJAX to get soft realtime values ββfrom a JSON file.
In fact, on my server, the C program updates the Json file with some information (200ms period). In my webpage, I am getting this Json file to display this information with a 250ms timer. I am using Ajax to get Json file.
The problem is the resizing of the Json file, for example:
My Json file:
{ "data1": { "val1": "12", "val2": "125"}, "data2": { "val1": "253", "val2": "0"} }
And become:
{ "data1": { "val1": "12", "val2": "14"}, "data2": { "val1": "253", "val2": "0"} }
Error occured, response from Ajax request:
{ "data1": { "val1": "12", "val2": "14"}, "data2": { "val1": "253", "val2": "0"} }\u0
"\ u0" appears to replace the missing character.
The same appears when the file gets longer, the answer is:
{ "data1": { "val1": "12", "val2": "14"}, "data2": { "val1": "253", "val2": "0"}
The last curly brace is missing.
My Javascript code for Ajax:
function getXMLHttpRequest() {
var xhr = null;
if (window.XMLHttpRequest || window.ActiveXObject) {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
} else {
xhr = new XMLHttpRequest();
}
} else {
alert("Your browser doesn't support the XMLHTTPRequest object ...");
return null;
}
return xhr;
}
function getDataAjax(callback, phpFile) {
xhr = getXMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
callback(xhr.responseText);
}
};
xhr.open("GET", phpFile, true);
xhr.send(null);
}
The Json file is correct, but there is no Ajax response.
Thank you for your help.
+3
source to share
No one has answered this question yet
Check out similar questions: