我是一个初学者和实验。我使用天气 API。我向该站点发送请求以获取有关天气的信息。
告诉我为什么控制台中没有显示任何内容,我做的一切正确吗?
var newRequest = new XMLHttpRequest();
newRequest.open("GET","http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22");
newRequest.onload = () => {
var ourWeather = JSON.parse(newRequest.responseText);
console.log(ourWeather);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<h1>JSON and AJAX</h1>
<button id="btn">Fetch info for 3 new animals</button>
</header>
你忘了实际发送请求
此外,本站不允许通过 AJAX 加载其页面,因为CORS