2
I need to change a json object that I am receiving. I would like to insert a data input into this Json. The idea is simple put a dice, it pulls the json according to this data, but I need to change the json with that same data. I need to change the johnner on apiGet! Follows Code:
<!DOCTYPE html>
<html>
<body>
<h1>Meu Projeto</h1>
<div id="id01"></div>
Nome: <input type="text" id="nome" value="johnner">
<p>Click the button to change the value of the text field.</p>
<button onclick="teste()">Try it</button>
<p id="saida">aqui</p>
<script>
function teste() {
var x = document.getElementById("nome").value;
var xmlhttp = new XMLHttpRequest();
var url = "https://na.api.pvp.net/api/lol/br/v1.4/summoner/by-name/" +
x + "?api_key=a15c56d1-fdd7-4da2-ad9c-0f1a6585ac1b";
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
apiGet(xmlhttp.responseText);
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
function apiGet(response) {
var XX = JSON.parse(response);
var arr = XX.johnner;
var out = "<h1>";
out += arr.id + arr.name + arr.summonerLevel;
out += "</h1>";
document.getElementById("id01").innerHTML = out;
}
function getImput() {
var x = document.getElementById("nome").value;
document.getElementById("saida").innerHTML = x;
}
</script>
</body>
</html>
I need to change/access Json for this part: var arr = XX.johnner;
using the same name that was passed in the ajax url.
AJAX returns this:
{"johnner":{"id":1111,"name":"Johnner","profileIconId":111,"summonerLevel":11,"revisionDate":1111111111}}
Perfect Sergião!!!!!!!!!!!!!!!! That’s what I wanted! I lack much knowledge yet!!! I will still modify the whole nomenclature put json in place of XX maybe and add more things. I’m still deepening.
– Johnner
:) I’m content to have helped (@Johnner)
– Sergio