Uncaught SyntaxError: Unexpected token:

0

I have a problem with the following code where the answer is this:

As you can see there is an answer but I get that error and it does not load me. Thanks in advance!

window.onload = function() {
	var mb = document.getElementById("myBtn");
	mb.addEventListener("click", jsonparser1);
}

function jsonparser1() {    
    $.ajax({
        type: "GET",
        url: "https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by-name/kappaequiscu1v9?api_key=RGAPI-9536b7c8-f23f-40a9-aea5-7a5bcd879205",
        dataType: "JSONP",
        success: function (xhr) {
			
			var response = JSON.parse(xhr.responseText);
			document.getElementById("span").innerText = response.accountId;
		}
    });
}  
<!DOCTYPE html>
<html>
<head>
	<title>DSFSF</title>
</head>
<body>

<h2>API KAPPAEQUISCU</h2>
<h3>Search:</h3>

<!--<input type="text" id="summoner">-->
<input type="submit" id="myBtn">

<h3>Response:</h3>

<span id="span"></span>
<span id="spanDos"></span>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="java.js"></script>

</body>
</html>
    
asked by Kappaequiscu 02.11.2017 в 21:37
source

1 answer

1

Hello, you have an error in ulr

but you should also see that the function is running as soon as the html is loaded.

the right thing would be

window.onload = function() {
    var mb = document.getElementById("myBtn");
    mb.addEventListener("click", jsonparser1);
}

function jsonparser1() {    
    $.ajax({
        type: "GET",
        url: "https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by-name/kappaequiscu1v9?api_key=RGAPI-9536b7c8-f23f-40a9-aea5-7a5bcd879205/",
        dataType: "JSONP",
        success: function (xhr) {

            var response = JSON.parse(xhr.responseText);
            document.getElementById("span").innerText = response.accountId;
        }
    });
}  

The error is that you have to complete the url with / ;

Greetings.

    
answered by 02.11.2017 в 23:41