Method to download xml by http access

I am not so good at English.
It may be hard to read to you, but, please forgive it.

I developed application before in c+.
l found cocoscreator, so I challenge development in javascript.

I want to make donwload(jpg,xml…etc) from http://example.jp/img01.jpg

when I developed by C+, i used like this↓↓↓

I found cocoscreator api 「Pipeline.Downloader」,「cc.loader.load 」.

but I am at a loss for usage.
In the first place, may I download files such as xml by「Pipeline.Downloader」?

I tried 「cc.loader.load 」like this↓↓↓

        var download_url = 'http://memopad.bitter.jp/w3c/xml/note.xml';            
        cc.loader.load(download_url,function() {console.log('now loading');}, function(err, tex) {
        })

but it didn’t work. (console log → Get data from file http://hotspring.webcrow.jp/tsukinomichikake/img/data.json failed)

if there is a method,Can you have you teach sample code and tell it in detail?

Pipeline is the underlying implementation for cc.loader, you shouldn’t use it directly.

cc.loader is for all the loading process, but in native environment, we have only implemented remote loading for images, not for text files. So if you want to download a text file and retrieve its content, please try the following code

var xhr = cc.loader.getXMLHttpRequest();
xhr.onload = function () {
    if(xhr.readyState === 4) {
        if (xhr.status === 200 || xhr.status === 0) {
            // handle xhr.responseText
        }
        else {
            // Failed
        }
    }
};
xhr.open("get", "http://memopad.bitter.jp/w3c/xml/note.xml", true);
xhr.send(null);
3 Likes

thank you for repley.
I used your sapmle code. It works!!

I appreciate your help.

With pleasure, enjoy

hi, i want to set a label that i have as a property. i want to set the label string as the object data that i retrieves from the url… please help