我想连一个天气预报的api, 但连接有问题.代码如下:
var data = document.getElementById("weather");
console.log(1);
function fun_weather(url){
var xhr = new XMLHttpRequest()
xhr.open("GET", url);
console.log(2);
console.log(xhr.readyState);
xhr.onreadystatechange = function(){
console.log(3);
switch(xhr.readyState){
case 0:
console.log("a");
break;
case 1:
console.log("b");
break;
case 2:
console.log("c");
break;
case 3:
console.log("d");
break;
case 4:
console.log("e");
data.innerHTML = xhr.responseText;
break;
}
console.log(4);
xhr.send();
}
}
fun_weather("https://free-api.heweather.com/s6/weather/forecast?location=chongqing&key=*");
console的信息:
可以看到程序到xhr.onreadystatechange就停了,难道是readystate没变吗?
SMILET
相关分类