当前位置: 首页 > news >正文

ajax访问阿里云天气接口,获取7天天气

$.ajax({url: 'https://ali-weather.showapi.com/day15',type: 'GET', // 或者 'POST',根据API要求dataType: 'json', // 预期服务器返回的数据类型headers: {'Authorization': "APPCODE c63ddd9d9f404df1913593131ff84a67",// 将'你的API密钥'替换为实际的API密钥'X-Requested-With': 'XMLHttpRequest' //跨域},crossDomain: true,  //跨域data: {area: area,},success: function (response) {// 请求成功时的回调函数console.log(response); // 处理返回的数据var dayList = response.showapi_res_body.dayList;if (dayList==null){alert("暂时无法获取天气数据")}else{var html = '';for(let i=1;i<8;i++){console.log(dayList[i]['daytime']);html += '<div class="weather-item" >'+'<div style="color: white">'+dayList[i]['daytime'].substring(4)+'</div>'+'<img class="weather-icon" src="'+dayList[i]['day_weather_pic']+'">'+'<div class="weather-temp" style="color: white">'+dayList[i]['day_air_temperature']+'℃</div></div>';}$('#weatherForecast').html(html);}},error: function (xhr, status, error) {// 请求失败时的回调函数console.error("An error occurred: " + error);}
});

注意空格是个坑

相关文章:

  • 相机Camera日志实例分析之三:相机Camx【视频光斑人像录制】单帧流程日志详解
  • JSON 与 AJAX
  • 安装配置以太链钱包工具
  • 解决 PyTorch 与 Python 3.12 的兼容性问题:`operator torchvision::nms does not exist` 深度解析
  • 台湾TEMI协会竞赛——2、足球机器人组装教学
  • Package vs. Directory (包 vs. 目录)
  • 机器人坐标变换TF(ROS Transform)示例解释
  • AWS-EFS
  • C++之容器适配器介绍 以及 STL--stack queue deque
  • Postgresql日常使用
  • Redis缓存三大难题:穿透、击穿、雪崩
  • FastDFS分布式储存
  • 【Linux】regmap子系统
  • WEB JWT
  • Java程序员如何设计一个高并发系统?
  • Go 语言安装指南:并解决 `url.JoinPath` 及 `Exec format error` 问题
  • 全栈监控系统架构
  • 大白话解释蓝牙的RPC机制
  • LeetCode 2917.找出数组中的K-or值
  • Linux612 chroot_list开放;FTP服务ftp:get put,指定上传路径报错553;ftp查看文件夹权限
  • 旅游投资公司网站建设/关键词查询爱站网
  • 中国移动idc建设网站/旅游推广赚佣金哪个平台好
  • 讯响模板网站/外链下载
  • 目前做哪个网站致富/北京关键词快速排名
  • 做建材外贸哪个网站比较好/永久免费的建站系统有哪些
  • wordpress在手机版/windows优化大师好用吗