-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);
}
错误意外标记是邮政编码和国家之间的逗号。
我猜应该是'+' –
的URL缺少一些报价 - >'“api.openweathermap.org/data/2.5/weather?zip= 94040,我们“' – Andreas
这不是一个相对的URL。它需要从一个方案开始(比如'http://') – Quentin