Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

XMLHttpRequest 在native或者模拟器下请求没反应

$
0
0

@xduooo 写道:

creator 1.3.2
浏览器下正常,在native或模拟器下没反应,也没错误日志

ajax: function(options){
if(!options.url)
{
	return;
}
options = options || {};
options.type = (options.type || "GET").toUpperCase();
options.dataType = options.dataType || "json";
options.timeout = options.timeout || 5000;
options.async = options.async || true;

var request = new XMLHttpRequest();
request.timeout = options.timeout;

request.onreadystatechange = function(){
	if(request.readyState == 4)
	{
		var status = request.status;
		if(status >= 200 && status < 400)
		{
			var data = request.responseText;
			cc.log(data);
			if(options.dataType == "json")
			{
				data = JSON.parse(request.responseText);
			}
			options.success(data);
		}
		else
		{
			options.error(status);
		}
	}
};

request.onerror = function(){
	options.error("net-error");
};

request.ontimeout = function(){
	options.error("timeout");
};

var params = null;
if(options.data)
{
	params = this.formatUrlParams(options.data);
}

if(options.type == "POST")
{
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}

request.open(options.type, options.url, options.async);
request.send(params);

}

帖子: 3

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>