XMLHttpRequest does not work with Javascript binding, why?

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

})();

JSB is not binging to these functions, please try schedule.

Shujun Qiao wrote:

JSB is not binging to these functions, please try schedule.

Thanks.
Could you give me more detailed info?
How to use schedule to download file?

We have a component called “assetManager”, which can be used to do version tracking and download files:)

Hao Wu wrote:

We have a component called “assetManager”, which can be used to do version tracking and download files:)

I saw that, thanks a lot!
But unlike the development head version, the AssetsManager in stable version 2.2.1 can only handle one package for one app.
Hope that cocos2d-x with newer AssetsManager version will be published soon.

Thanks for your help.