[英]Building an API with node and express, how to get json data from a url?
[英]How to get data from json api url?
我试图使用jQuery.getJSON()获取数据,但是它不起作用。
我想从以下网址获取数据: http : //www.posta.com.tr/api/LiveScore/LeagueStageFixture? TournamentID =1& includeFixture =1
这是我尝试的:
JS
$.getJSON("http://www.posta.com.tr/api/LiveScore/LeagueStageFixture?TournamentID=1&includeFixture=1", function(data) {
$('#data').text(data.result);
});
的HTML
<div id="data"></div>
如何获取数据并将其显示在div中?
请尝试这个。
$.ajax({
url: "http://www.posta.com.tr/api/LiveScore/LeagueStageFixture",
type: "get", //send it through get method
headers:{
"Access-Control-Allow-Origin": "*"
},
data:{
TournamentID: 1,
includeFixture: 1
},
success: function(response) {
//Do Something
},
error: function(xhr) {
//Do Something to handle error
}
});
现在可以使用php了。 问题是域阻止了来自不同主机的连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.