Problem z pobieraniem danych z League of Legends

0

Mam taki kod:

var settings = {
  "url": "https://eun1.api.riotgames.com/lol/summoner/v4/summoners/by-name/Wykreuje%20cie?api_key=RGAPI-c22cbd79-b7c8-4028-8383-e46e2b8cdf76",
  "method": "GET",
  "timeout": 0,
  "dataType" : "jsonp",
  "Content-Type": "text/html;charset=utf-8"
};




$.ajax(settings).done(function (response) {
	console.log("dupa");
	var obj = JSON.parse(response); 
	for(var i=0;i<obj.length;i++){
		console.log(obj.name);
	}
		
});

i na konsole wywala mi takie coś:
screenshot-20190608165041.png

chcę to co mi zczyta po prostu wyświetlić name obiektu.

Help :)

1

Trochę próbowałem i jedyne na co wpadłem i zadziałało to coś takiego:

const proxyurl = "https://cors-anywhere.herokuapp.com/";
const url = "https://eun1.api.riotgames.com/lol/summoner/v4/summoners/by-name/Wykreuje%20cie?api_key=RGAPI-c22cbd79-b7c8-4028-8383-e46e2b8cdf76";
fetch(proxyurl + url)
.then(response => response.json())
.then(contents => console.log(contents))
.catch(() => console.log("Can’t access " + url + " response"))

Demo - https://jsfiddle.net/0vbjan48/2/
Z tym cors, to zawsze jest trochę zabawy, ale to powinno bez problemu działać.
Uwzględniając twój kod, całość będzie wyglądała tak

const proxyurl = "https://cors-anywhere.herokuapp.com/";
const url = "https://eun1.api.riotgames.com/lol/summoner/v4/summoners/by-name/Wykreuje%20cie?api_key=RGAPI-c22cbd79-b7c8-4028-8383-e46e2b8cdf76";
fetch(proxyurl + url)
.then(response => response.json())
.then(contents => {
    console.log("dupa");
    var obj = contents;
    for (key in obj) {
        console.log(key);
    }
    }
 )
.catch(() => console.log("Can’t access " + url + " response"))

Demo - https://jsfiddle.net/vcpr21xs/

Nie dziękuj, kwiaty wystarczą

0

Wystarczy ustawić mode: 'no-cors' i działa... nie wiem jak to jest z tym jquery ale pewnie też jest taka opcja :/

const url = 'https://eun1.api.riotgames.com/lol/summoner/v4/summoners/by-name/Wykreuje%20cie?api_key=RGAPI-c22cbd79-b7c8-4028-8383-e46e2b8cdf76'

fetch(url, {mode: 'no-cors'})
	.then(response => {
		return response.json()
	})
	.then(console.log)
	.catch(console.error)

1 użytkowników online, w tym zalogowanych: 0, gości: 1