Cocos

2018-05-24 cocos creator里面post请求

2018-05-24  本文已影响58人  工匠良辰

post请求一直传送不了数据,解决方案如下:xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http post请求

let url = 'http://127.0.0.1:3000/create';
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
                var response = xhr.responseText;
                console.log("http data返回:", response);
                var resData = JSON.parse(response);
                
            }
        };
        xhr.open("POST", url, true);
        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        var sdata={
            data: [1,2,3]
        };
        console.log('post data:', sdata);
        xhr.send( 'data=[1,2,3]');
上一篇下一篇

猜你喜欢

热点阅读