On my page I make two calls to json from the same API but different resources:
function buscaInvocador($nombre) {
$.ajax({
url: "https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by-name/$nombre?api_key=RGAPI-de016c14-78f2-4e19-82a7-33526d8bed4c",
dataType: "json",
}).done(function() {
$('.idInvocador').append("Hola");
}).fail(function() {
$('.idInvocador').append("Adios");
})
}
This url does not work, it always enters the .fail
but I'm sure it returns the JSON (the url in the browser works and it looks like the json returns) .
{"id": 97938335, "accountId": 232092599, "name": "Ka0x14", "profileIconId": 1627, "revisionDate": 1491345737000, "summonerLevel": 12}
On the other hand, this call to url if it works correctly. jquery detects me the json and I can play with him.
The call always enters the .done
function buscaMaestria($id) {
$.ajax({
url: "https://euw.api.riotgames.com/api/lol/EUW/v1.4/summoner/$id/masteries?api_key=RGAPI-de016c14-78f2-4e19-82a7-33526d8bed4c",
dataType: "json",
}).done(function() {
$('.idInvocador').append("Hola");
}).fail(function() {
$('.idInvocador').append("Adios");
})
}
The resulting json is as follows.
{"23385178":{"summonerId":23385178,"pages":[{"id":34451272,"name":"Thresh","current":false,"masteries":[{"id":6342,"rank":1},{"id":6241,"rank":1},{"id":6311,"rank":5},{"id":6221,"rank":1},{"id":6211,"rank":5},{"id":6322,"rank":1},{"id":6332,"rank":5},{"id":6232,"rank":5},{"id":6362,"rank":1},{"id":6352,"rank":5}]},{"id":34451273,"name":"Alistar","current":false,"masteries":[{"id":6342,"rank":1},{"id":6311,"rank":5},{"id":6241,"rank":1},{"id":6221,"rank":1},{"id":6211,"rank":5},{"id":6322,"rank":1},{"id":6332,"rank":5},{"id":6231,"rank":5},{"id":6352,"rank":5},{"id":6362,"rank":1}]},{"id":34451274,"name":"Tahm","current":false,"masteries":[{"id":6342,"rank":1},{"id":6223,"rank":1},{"id":6311,"rank":5},{"id":6241,"rank":1},{"id":6211,"rank":5},{"id":6263,"rank":1},{"id":6322,"rank":1},{"id":6332,"rank":5},{"id":6232,"rank":5},{"id":6252,"rank":5}]},{"id":34451275,"name":"Karma","current":false,"masteries":[{"id":6223,"rank":1},{"id":6342,"rank":1},{"id":6241,"rank":1},{"id":6311,"rank":5},{"id":6322,"rank":1},{"id":6332,"rank":5},{"id":6212,"rank":5},{"id":6231,"rank":5},{"id":6363,"rank":1},{"id":6352,"rank":5}]},{"id":34451276,"name":"Bardo","current":false,"masteries":[{"id":6223,"rank":1},{"id":6342,"rank":1},{"id":6241,"rank":1},{"id":6311,"rank":5},{"id":6331,"rank":5},{"id":6211,"rank":5},{"id":6322,"rank":1},{"id":6351,"rank":5},{"id":6232,"rank":5},{"id":6362,"rank":1}]},{"id":34451279,"name":"Pág. de maestrías 8","current":false,"masteries":[{"id":6121,"rank":1},{"id":6343,"rank":1},{"id":6111,"rank":5},{"id":6321,"rank":1},{"id":6331,"rank":5},{"id":6142,"rank":1},{"id":6312,"rank":5},{"id":6162,"rank":1},{"id":6134,"rank":5},{"id":6151,"rank":5}]},{"id":34451280,"name":"Mastery Page 9","current":false,"masteries":[{"id":6223,"rank":1},{"id":6342,"rank":1},{"id":6241,"rank":1},{"id":6311,"rank":5},{"id":6211,"rank":5},{"id":6322,"rank":1},{"id":6332,"rank":5},{"id":6231,"rank":5},{"id":6363,"rank":1},{"id":6352,"rank":5}]},{"id":34451281,"name":"Ivern","current":true,"masteries":[{"id":6343,"rank":1},{"id":6114,"rank":5},{"id":6134,"rank":4},{"id":6122,"rank":1},{"id":6331,"rank":5},{"id":6312,"rank":5},{"id":6322,"rank":1},{"id":6143,"rank":1},{"id":6351,"rank":5},{"id":6131,"rank":1},{"id":6362,"rank":1}]}]}}
Both functions are exactly the same, the only thing that varies is the url of the resource of the api. The resulting jsons have a different format and I may have to specify the format of the json in the data of my function, but I do not have much idea of this.
The variable $nombre
I put it so we know that there goes a variable value. I do the tests with " Ka0x14
". In the browser the json returns it to me, but the function fails me.