I want to update js/res files when booting by calling:
var response = readText(“http://httpbin.org/get”);
But in readFile, the xhr status is alwayws 0xCDCDCDCD, so code “throw ‘failed to open:’ + url;” will be excuted and then stop running.
Same code works well in HTML5.
Does any one know how to fix the problem?
Thanks in advance!
My code list:
var readFile = function (url, mimeType) {
var xhr = new XMLHttpRequest();
xhr.open(“GET”, url, false);
if (mimeType != null) {
xhr.overrideMimeType(mimeType);
}
xhr.send(null);
cc.log(“xhr.status:” + xhr.status);
if (xhr.status = 0) {
throw ‘failed to open:’ + url;
}
return xhr.responseText;
};
var readBinary = function (url) {
var stringy = readFile(url, ‘text/plain; charset=x-user-defined’);
var data = new Array(stringy.length + 1);
var i;
for (i = 0; i < stringy.length; i++) {
data[i] = stringy.charCodeAt(i) & 0xff;
}
data[stringy.length] = 0;
return data;
};
var readText = function (url) {
return readFile(url);
};
var readXML = function (url) {
return readFile(url, “application/xml”);
};
(function () {
cc.log(“Update: started”);
// TODO: Get version.json
var response = readText(“http://httpbin.org/get”);
cc.log(“Status: Got GET response!” + response);
// TODO: For each entry, compare local version in localStorage with lastest version in version.js
// TODO: Update files
// TODO: Set search path
})();