2017-02-21 5 views
-2

Open Weather API를 호출 할 때 콘솔에 예기치 않은 토큰 오류가 발생합니다.예기치 않은 토큰 ','api call ajax

function ajaxCall() { 
    var xhttp = new XMLHttpRequest(); 
    xhttp.open("POST", api.openweathermap.org/data/2.5/weather?zip=94040,us); 
    xhttp.setRequestHeader("Content-type", "application/json"); 
    xhttp.send(); 
    var response = JSON.parse(xhttp.responseText); 
    console.log(response); 
} 

예기치 않은 토큰은 우편 번호와 국가 사이의 쉼표입니다.

+0

나는'+' –

+2

URL은 일부 인용 부호가 누락해야한다 생각 ->' "api.openweathermap.org/data/2.5/weather?zip= 94040, us " – Andreas

+0

이것은 상대 URL이 아닙니다. (http : //와 같은) scheme으로 시작할 필요가있다. – Quentin

답변

0

URL에 따옴표가 없습니다. 변경 :

xhttp.open("POST", api.openweathermap.org/data/2.5/weather?zip=94040,us); 

에 :

xhttp.open("POST", "api.openweathermap.org/data/2.5/weather?zip=94040,us");