简体   繁体   中英

How to get data from json api url?

I tried to get the data with the jQuery.getJSON() but it doesn't work.

I want to get the data from this url: http://www.posta.com.tr/api/LiveScore/LeagueStageFixture?TournamentID=1&includeFixture=1

This is what I tried:

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>

How can I get the data and show it in a div?

please try this.

$.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
  }
});

It works now with php. The problem was that the domain blocks connection from different hosts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM