if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest();} IE6 {//代码,IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");} xmlhttp.open("GET",“http://finance.yahoo.com/d/quote.csve=.csv&s=^BSESN&f=nl1c2vgh&random=10",true”);xmlhttp.send(null);xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { window.alert(xmlhttp.status);}}
的上述代码显示状态200在IE,但在火狐和Chrome获得了状态0应有的跨域功能。有谁能帮助使用java脚本.克服这种跨域功能吗?
发布于 2012-11-23 11:27:02
由于跨域问题,无法从JavaScript ajax直接调用其他域,进行这种类型调用的最佳方法是使用Ajax调用自己的网页,并从服务器端脚本调用这些apis并获得答案并返回到ajax调用。
如果您使用php,您可以使用file_get_contents cURL或从url中获取内容。
https://stackoverflow.com/questions/13534656
复制