【前端学习笔记】2015-09-11~~~~ js中ajax请求返回案例
<body>
<textarea id='a' rows=100 cols=300>result:</textarea>>
<script>
var a=document.getElementById("a");
var http1=new XMLHttpRequest;
http1.open("GET","http://apis.baidu.com/heweather/weather/free?city=zhengzhou&output=jsonp");
http1.setRequestHeader('apikey','7d3fd5fb844142b3e3e8862469d73b6f');//setRequestHeader('键',‘值’)的写法要记住
http1.send(true);
http1.onreadystatechange=function(){
if(http1.readyState===4){
if(http1.status===200){
return a.innerHTML=http1.responseText;}}};
</script>
</body>
只能在dw中显示,Request header field apikey is not allowed by Access-Control-Allow-Headers.在浏览器中报这个错,等下周回来看下