I’m working with some local json files but I’m having some problems with the loading speed. My server is just a little webserver made with python and I usually use it for trying my javascript code.
My script works only with Firefox and I have to put a delay of 60000 ms (or use firebug).
The script is:
function geisson()
{
var iabile = new XMLHttpRequest();
iabile.open("GET", "longanocard.json", true);
iabile.send(null);
PerdiTempo(60000);
var objectjson = {};
var arrayCards= []; //creazione dell'array che conterrà le cards
objectson = JSON.parse(iabile.responseText);
arrayCards = objectson.cards;
//alert(arrayCards[0].__guid__.toSource());
var qwerty = arrayCards[0].__guid__;
var mela = "http://www.airpim.com/png/public/card/" + qwerty + "?width=292";
document.location = mela;
//windows.location.href= mela;
}
PerdiTempo is the function I use for the delay:
function PerdiTempo(ms)
{
ms += new Date().getTime();
while (new Date() < ms){}
}
How can I speed up the loading of the file longanocard.json? Why the delay doesn’t work with other browsers?
You should really avoid to wait an asynchronous response in that way (how do you know exactly how much seconds delay the JSON parsing?), using instead the
onreadystatechangeevent for your request