YangYoona 2017-07-31 12:07 采纳率: 5.6%
浏览 1410
已采纳

html5 ajax 访问百度云接口的问题

<!DOCTYPE html>



title here ajax





a
<br> function show(){<br> CreateXmlHttp();<br> if(!xhr){<br> alert(&quot;创建xmlhttp对象异常&quot;);<br> return false;<br> }<br> xhr.open(&quot;POST&quot;, &quot;<a href="https://aip.baidubce.com/oauth/2.0/token%22">https://aip.baidubce.com/oauth/2.0/token&quot;</a>);<br> xhr.setRequestHeader(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);<br> xhr.onreadystatechange = function () {<br> if(xhr.readyState == 4){<br> document.getElementById(&quot;dd&quot;).innerHTML = &quot;数据正在加载。。。&quot;+xhr.status;<br> if(xhr.status == 200){<br> document.getElementById(&quot;write&quot;).innerHTML = xhr.responseText;<br> }else{<br> document.getElementById(&quot;write&quot;).innerHTML = &quot;不能够进行跨域请求。&quot;;<br> }<br> }<br> }</p> <pre><code> xhr.send(&#39;grant_type=client_credentials&amp;client_id=mfnwFRuO5EOewQON0piojoNR&amp;client_secret=3aDW6TU1nZ7mDsAx5zjvz75WPVyx6LeG&#39;); } function CreateXmlHttp(){ //非IE浏览器创建XmlHttpRequest对象 if(window.XMLHttpRequest){ xhr = new XMLHttpRequest(); } //IE浏览器创建XmlHttpRequest对象 if(window.ActiveXObject){ try{ xhr = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;); }catch(e){ try{ xhr = new ActiveXObject(&quot;msxml2.XMLHTTP&quot;); }catch(ex){ } } } } &lt;/script&gt; &lt;/body&gt; </code></pre> <p></html></p> <p>这是代码,大神门看一看怎么改浏览器就都能访问啦,手机上也需要能访问,现在只有IE浏览器能访问</p>
  • 写回答

1条回答

  • Go 旅城通票 2017-08-01 01:56
    关注

    跨域了没搞,ie能跨域你肯定是配置过通过域访问数据源(就是允许ie跨域请求其他资源),否则照样报过错

    要在服务器端请求接口,如果接口支持jsonp自己看说明,或者支持get请求,用yql转为jsonp数据不需要经过服务器端

    JSONP跨域访问在线代理API

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料