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

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

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题