码迷,mamicode.com
首页 > Web开发 > 详细

【前端学习笔记】2015-09-11~~~~ js中ajax请求返回案例

时间:2015-09-11 20:46:46      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

<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.在浏览器中报这个错,等下周回来看下

【前端学习笔记】2015-09-11~~~~ js中ajax请求返回案例

标签:

原文地址:http://www.cnblogs.com/zipon/p/4801880.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!