在 HTTP URL (JSFiddle) 上使用 getJSON 时如何修复混合内容错误?
How do I fix a mixed content error when using getJSON on a HTTP URL (JSFiddle)?
我正在尝试在 JSFiddle 中使用 getJSON,但是由于 JSFiddle 使用 HTTPS,而我作为参数使用的 URL 使用 HTTP,因此存在混合内容错误:
代码:
$.getJSON('http://swapi.co/api/people/2/?format=json', function(C3P0) {
alert(C3P0.mass)
})
错误:
jquery-3.1.0.js:9392 混合内容:位于“https://jsfiddle.net/Rubyleaf_MBarton/g802f6yL/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://swapi.co/api/people/2/?format=json”的页面。此请求已被阻止;内容必须通过 HTTPS 提供。
jquery-3.1.0.js:9392 XMLHttpRequest 无法加载 http://swapi.co/api/people/2/?format=json。无法开始加载。
我可以修复这个错误吗?
swapi.co
也支持https
。最好是向 API:
的安全版本发出请求
$.getJSON('https://swapi.co/api/people/2/?format=json', function(C3P0) {
alert(C3P0.mass)
})
这样您的代码将适用于 http
和 https
协议。
我正在尝试在 JSFiddle 中使用 getJSON,但是由于 JSFiddle 使用 HTTPS,而我作为参数使用的 URL 使用 HTTP,因此存在混合内容错误:
代码:
$.getJSON('http://swapi.co/api/people/2/?format=json', function(C3P0) {
alert(C3P0.mass)
})
错误:
jquery-3.1.0.js:9392 混合内容:位于“https://jsfiddle.net/Rubyleaf_MBarton/g802f6yL/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://swapi.co/api/people/2/?format=json”的页面。此请求已被阻止;内容必须通过 HTTPS 提供。
jquery-3.1.0.js:9392 XMLHttpRequest 无法加载 http://swapi.co/api/people/2/?format=json。无法开始加载。
我可以修复这个错误吗?
swapi.co
也支持https
。最好是向 API:
$.getJSON('https://swapi.co/api/people/2/?format=json', function(C3P0) {
alert(C3P0.mass)
})
这样您的代码将适用于 http
和 https
协议。