En mi página hago dos llamadas a json de la misma API pero distintos recursos:
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");
})
}
Esta url no funciona, siempre entra en el .fail
pero estoy seguro de que me devuelve el JSON (la url en el navegador funciona y se ve como devuelve el json).
{"id":97938335,"accountId":232092599,"name":"Ka0x14","profileIconId":1627,"revisionDate":1491345737000,"summonerLevel":12}
Por otro lado, esta llamada a url si funciona correctamente. jquery me detecta el json y puedo jugar con el.
La llamada siempre entra en el .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");
})
}
El json resultante es el siguiente.
{"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}]}]}}
Ambas funciones son exactamente iguales, lo único que varía es la url del recurso de la api. Los json resultantes tienen formato distinto y quizás tenga que especificar en el data de mi función el formato del json, pero no tengo mucha idea de esto.
La variable $nombre
la pongo para que sepamos que ahí va un valor variable. Las pruebas las hago con "Ka0x14
". En el navegador el json me lo devuelve, pero la función me falla.
dani
te sale un json válido