case 4:
if ( xhr.status == 200 ) {
var text = document.getElementById("text");
text.innerHTML = "xhr请求成功";
console.log(xhr.response);
console.log(xhr.responseType);
console.log(xhr.responseText);
if(xhr.response.valueOf("update")) {
} else {
}
} else {
var text = document.getElementById("text");
text.innerHTML = "xhr请求失败";
}
break;
default :
break;
在执行这段代码是输出是如下:
应用HBuilder已启动...
null at index.js:42
json at index.js:43
{"update":true,"version":"1.0","title":"TestApplication","name":"测试应用","entry":"index.html","description":"测试应用的第一个版本","downloadurl":"http://","serveraddress":"http://","file":[B@440faed3} at index.js:44
Uncaught TypeError: Cannot call method 'valueOf' of null at index.js:45
可以看到代码执行到第二个if判断时报了错,可是我明明在new xhr时已经执行type为json,为什么收到的xhr,response还是null呢?
1 个回复
最佳回复
Android_磊子
服务器返回数据必须为标准json格式,即key、value均添加双引号如:{"key","value"}