@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