ajax,jsonp跨域访问数据

时间:2024-06-23 12:34:02

访问高德aip天气接口

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="jquery.js" charset="utf-8"></script>
<script>
$.ajax({
url: 'https://restapi.amap.com/v3/weather/weatherInfo?city=洛阳市&key=830cbacb691a45d2bfc1eca2d43289ee',
dataType: 'jsonp',
success(res){
$("#div1").html(JSON.stringify(res.lives[0]))
},
error(){
alert('错了');
}
});
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>