* Get 请求服务器
* @param {String} url 地址
* @param {JSON} data 数据JSON
* @param {Function} callback 回调函数 JSON对象
*/
app.get = function(type, url, callback) {
var t = null;
var xhr = new plus.net.XMLHttpRequest();
xhr.onreadystatechange = function() {
switch (xhr.readyState) {
// case 0:
// alert("xhr请求已初始化");
// break;
// case 1:
// alert("xhr请求已打开");
// break;
// case 2:
// alert("xhr请求已发送");
// break;
// case 3:
// alert("xhr请求已响应");
// break;
case 4:
alert(xhr.responseText);
if (xhr.status == 200) {
var result = null;
if (xhr.responseText != undefined && xhr.responseText != "")
result = app.getJSONObj(xhr.responseText);
if (typeof callback == "function") {
callback(result);
}
} else {
alert("xhr请求失败:" + xhr.status);
}
break;
default:
break;
}
}
if (type == "server")
url = app.getServerUrl(url);
if (type == "res")
url = app.getResUrl(url);
t = url;
xhr.open("GET", url);
xhr.send();
}
xhr请求失败:406
求大神解决
1 个回复
DCloud_App_Array
请确认传输内容的字符集编码格式,并在http头中返回正确的content-type,如果没有返回正确的content-type,请使用overrideMimeType方法设置正确的字符集编码格式(charset=xxx),参考规范:
http://www.html5plus.org/doc/zh_cn/xhr.html#plus.net.XMLHttpRequest.overrideMimeType