【发布时间】:2014-11-20 07:01:18
【问题描述】:
我想创建一个自动完成功能,我需要来自不同网站的数据作为源。因此,当我手动访问链接时,我想创建一个 Ajax 请求作为第一步,它只返回 JSon 字符串(我认为它是 Json)。由于“允许来源”的事情,我遇到了一些错误。
这是我从中获取所有数据的链接:
http://www.futhead.com/15/players/search/quick/?term=
最后(在 term= 之后)我想稍后添加我的自动完成字段的输入,这个链接返回我的不同结果。
这是我在谷歌搜索后尝试过的,它会提示“错误”:
$.ajax({
url:"http://www.futhead.com/15/players/search/quick/",
data: "term=Ibarbo",
dataType: 'jsonp', // Notice! JSONP <-- P (lowercase)
success:function(json){
// do stuff with json (in this case an array)
alert("Success");
},
error:function(){
alert("Error");
}
});
我想要什么:
我想在我的 php 文件中显示这个页面的结果,按属性排序。
这是“http://www.futhead.com/15/players/search/quick/?term=ibarbo”的结果:
[{"rating": 75, "club_image": "http://futhead.cursecdn.com/static/img/15/clubs/1842.png", "image": "http://futhead.cursecdn.com/static/img/15/players/204550.png", "revision_type": null, "workrates_short_string": "M/M", "xb_auction_average": null, "full_name": "V\u00edctor Ibarbo", "player_id": 204550, "id": 816, "nation_image": "http://futhead.cursecdn.com/static/img/15/nations/56.png", "pc_auction_average": null, "type": "15-player", "short_name": "V\u00edctor Ibarbo", "ps_auction_average": null, "club": 363, "nation": 12, "attr6": 78, "attr4": 80, "attr5": 39, "attr2": 71, "attr3": 66, "attr1": 91, "slug": "victor-ibarbo", "league": 1, "rare": true, "level": 0, "position": "ST"}]
那我要输出:
评分 = 75
Club_image = http://futhead.cursecdn.com/static/img/15/players/204550.png
等等。
【问题讨论】: