https页面发送http请求报错

搭建新的松鼠工具箱时,换了了新主题,有个模块无法显示,即天气模块,查看XHR时发现问题。调用天气api时状态为 blocked:mixed-content

相关js代码如下:

$(document).ready(function(){
    //天气卡片
    var weather = 'http://tianqiapi.com/api';
    $.ajax({
    	type: "GET",
    	url: weather,
    	data: {
    		appid: '58848727',
    		appsecret: 'W8tVhX1B',
    		version: 'v6',
    	},
    	dataType: "json",
    	success: function(data) {
    		var wea_bg = '<img src="http://www.nuandao.cn/images/ndnav/'+ data.wea_img + '.jpg" />'
    		$('.wea_img').append(wea_bg)
    		$('.wea_city span').html(data.city)
    		$('.wea_tem').html(data.tem)
    		$('.wea_other .date').append(data.date)
    		$('.wea_other .week').append(data.week)
    		$('.wea_other .wea').append(data.wea)
    		$('.wea_other .win').append(data.win)
    		$('.wea_other .win_speed').append(data.win_speed)
    		//console.log(data)
    	}
    });
});

CSDN上解释:https页面发送http请求报错(浏览器阻止https发送http请求)

那就改,将http://tianqiapi.com/api改为https://tianqiapi.com/api
顺便将图片调用地址改为https://tools.jishusongshu.com/images/ndnav/
结果是天气详情是显示出来了,但是图片还是不显示

我以为是文章伪静态问题,于是采用图片OSS托管:https://cdn.jishusongshu.com/images/ndnav/

后记

12月15日天气api接口不可用,v6版本估计被遗弃了。

参考最新的专业实况天气接口,修改以下参数即可。

var weather = 'https://v0.yiketianqi.com/api'

version: 'v61'
后来发现接口失效了,原来调用的是付费接口:

{
  errcode: 100,
  errmsg: "v61接口测试次数已用完,付费365一年可每日10万次,客服qq:445899710"
}

解决方法:改回https://tianqiapi.com/apiversion: 'v6'

本文采用 CC BY-NC-SA 3.0 Unported 许可,转载请以超链接注明出处。
原文地址:https页面发送http请求报错 作者:松鼠小
暂无评论
本文评论已关闭
上一篇
下一篇