Cocos2d-js xhr XMLHttpRequest

i have:
var xhr = cc.loader.getXMLHttpRequest();
xhr.onreadystatechange = function (){
cc.log("state: " + xhr.readyState);
cc.log("status: " + xhr.statusText);
cc.log("response1: " + xhr.responseText);
if (xhr.readyState == 4 && (xhr.status == 200)) {
cc.log("response2: " + xhr.responseText);
}
else if (xhr.status == 400) {

        }
    }
    xhr.timeout = 10000;
    xhr.open('POST', gateJson.info[gameIndex].api.tranferVcoinToStar, false);
    xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
    xhr.setRequestHeader('cookie', cookie);
    cc.log("cookie: " + cookie);
    var vcoindemo = parseInt(_edbVcoin.getString())
    cc.log("url: " + gateJson.info[gameIndex].api.tranferVcoinToStar);
    var demo = JSON.stringify({
        vcoin: vcoindemo
    });
    cc.log("demo: " + demo);
    xhr.send(JSON.stringify({
        vcoin: vcoindemo
    }));

when i try to run it, it have problem:

JS: response1:

Bad Request

Bad Request


HTTP Error 400. The request is badly formed.

Can you help me, plzzzzzzzzzzzzzzzz

Hello all,

Getting similar error when we pass large data as JSON converted using JSON.stringify(), Any one solved it??
And can we use FormData() for MultiPart the data and HOW??

Regards,
Sriby7

Hi all,

I got a solution for this problem.
you need to open xhr with half of the API(BaseUrl) call like

var xhr = cc.loader.getXMLHttpRequest();
xhr.open(“POST”, BaseUrl);

then create one variable with all the other data variables converted to the string or also JSON.stringify() data can also merge with this and pass it as a parameter to send() like :

xhr.send(data);

by this, you can send larger data at a time to API servers.

Regards,
sriby7