请问怎么跨域请求json数据?
javascript吧
全部回复
仅看楼主
level 3
ontseason 楼主
例如我想访问这个页面中的数据 http://contests.acmicpc.info/contests.json
这样
和这样
$(document).ready(function(){
$.ajax({
type: "get",
async: false,
url: "http://contests.acmicpc.info/contests.json",
dataType: "json",
jsonp: "callback",//传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(一般默认为:callback)
jsonpCallback:"?",//自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名,也可以写"?",jQuery会自动为你处理数据
success: function(json){
alert("链接成功");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("failed");
}
});
都失败了
2014年10月18日 07点10分 1
level 4
用iframe,这是我目前的解决办法。如果是你自己的站 输出callback(json数据);
2014年10月18日 09点10分 2
level 4
楼上正解 . 不带callback的话 不行滴..
2014年10月18日 13点10分 4
好吧
2014年10月18日 13点10分
level 11
getJson
2014年10月18日 17点10分 5
getJSON是需要服务端支持的吧?
2014年10月19日 13点10分
level 11
还有一个办法是服务端设置允许跨站访问
2014年10月18日 22点10分 6
level 7
试试CORS
2014年10月19日 06点10分 7
level 12
不知道
2014年10月19日 12点10分 8
level 4
通过标签<script>中的src这个属性可以跨域访问。这个我之前遇到过,当时是写百度调用接口,然后跨域加载再回调函数。就可以了。
2014年10月19日 12点10分 9
jsonp?
2014年10月19日 13点10分
回复 ontseason :http://developer.51cto.com/art/201110/298633.htm代码中涉及到了跨域访问的问题。
2014年10月21日 04点10分
level 5
frame call
script call //不适合你当前情况
flash call //需要自己写as
觉得哪种适合用哪种
2014年10月20日 04点10分 10
level 7
写ajax前提得懂PHP与js吧
2014年10月22日 10点10分 11
ajax和php有毛线关系, 我用Python
2014年10月22日 11点10分
python或者PHP,起码得用一种后端吧,不然ajax怎么整?
2014年10月23日 09点10分
level 12
楼主用的是什么编辑器啊
2014年10月23日 13点10分 12
sublimetext
2014年10月24日 02点10分
level 9
跨域访问使用jsonp,或者用动态添加script元素,jsonp也是添加script元素来完成
2014年10月23日 14点10分 13
知道了。。但也需要服务端支持对吧?
2014年10月24日 02点10分
回复 ontseason :对的,需要服务器提供指定功能,如果服务器不支持你需要自己做服务器转接
2014年10月24日 02点10分
回复 spiniper :服务器转接是什么。。。google了一下,没找到相关的信息
2014年10月25日 00点10分
回复 ontseason :就是你自己用服务器读取对方网站信息在转发,让域一致
2014年10月25日 11点10分
level 12
顺道顶一下-------这样应该就能凑齐标准的
十五字

2014年10月23日 15点10分 14
level 10
用 JSONP
2014年11月06日 15点11分 15
level 10
jsonp或者script
2014年11月06日 23点11分 16
level 1
#(pic,76094b36acaf2edd36139c878e1001e9380193fa,600,600)
2014年11月08日 11点11分 17
1