I need to change a json Object that I'm receiving. I would like to insert a data of an input in this Json. The idea is simple put a data, it pulls the json according to this data, but I need to change the json with that same data. I need to change johnner in apiGet! Follow 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 in 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}}