当前位置: 首页 > 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);}
});

注意空格是个坑

http://www.xdnf.cn/news/1002169.html

相关文章:

  • C++ 引用
  • get_attribute的使用方法
  • 【小根堆】P9557 [SDCPC 2023] Building Company|普及+
  • Spring Cloud Gateway + OAuth2 + JWT 单点登录(SSO)实现方案
  • Java八股文——MySQL「SQL 基础篇」
  • 随记:sw2urdf插件导出urdf模型在ROS2-rviz2显示
  • 在Vue2项目中引入ElementUI详细步骤
  • Linux系统下安装elasticsearch6.8并配置ik分词
  • 【Java】浅谈ScheduledThreadPoolExecutor
  • Python实战应用-Python实现Web请求与响应
  • 智能合约的浪潮:从区块链到业务自动化的 IT 新引擎
  • 服务器-客户端下kafka的消息处理流程
  • Vue3+PDF.js 实现高性能 PDF 阅读器开发实战
  • C# 动态管理控件和事件,批量查询管理同类控件
  • JavaWeb期末速成 JSP
  • 浅谈DaemonSet
  • PRIMES“中国校准实验室”正式运营,携手东隆科技共筑精准测量新标准
  • 通过同步压缩小波变换实现信号的分解和重构
  • 概率论几大分布的由来
  • 基于STM32汽车温度空调控制系统
  • Unity-通过Transform类学习迭代器模式
  • 数据集-目标检测系列- 孔雀 数据集 peacock >> DataBall
  • FFmpeg 压缩视频文件
  • 力扣HOT100之技巧:136. 只出现一次的数字
  • C#调用C++ 结构体方法
  • GitHub 上 PAT 和 SSH 的 7 个主要区别:您应该选择哪一个?
  • Transformer 与 XGBoost 协同优化的时间序列建模
  • LSTM助力迁移学习!深度学习架构性能提升,准确率达到99.91%!
  • TCN+Transformer+SE注意力机制多分类模型 + SHAP特征重要性分析,pytorch框架
  • 用于在多个远程计算机上求解的 Ansoft RSM 设置 - Windows