Forums / Developer Forum
Order: Newest / Oldest
JQuery $.ajax
AmIfootball (Chelsea) 2 years ago
Hey guys,

Has anyone managed to use jQuery to fetch data via the api/json.

I'm running a $.AJAX function but for some reason I am struggling to get data back!



$ft_api_key="**secret**";
$ft_api_url="Link: api.openfooty.org/1.0/ ";
$ft_api_getFixtures="league.GetFixtures";
$ft_api_league_id=8;
$ft_api_format="json";

$.Ajax ({
Type: "get",
Url: $ft_api_url+$ft_api_getFixtures,
Data: ({api_key: $ft_api_key, league_id: $ft_api_league_id, format:$ft_api_format}),
Success: function(data){alert("this call works");},
Async: false,
DataType: "json"
});
Return false;
GarfLloydell (FC København) 2 years ago
I'd guess you're running into cross domain request issues. Basically you're not allowed to send an ajax request from one domain to another, it's possible to pull off but it requires a decent amount of trickery.

Just out of curiosity, why are you trying to load openfooty data with javascript instead of grabbing it with some backend logic and displaying it from your server?
AmIfootball (Chelsea) 2 years ago
Thanks Garf. Yea, I was just messing around and trying to get something that worked asap. After a bit of scrambling around I learnt about the cross domain issue, the hard way



   
Kick4Life - changing lives through football