Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This request has been blocked; the content must be served over HTTPS

Tags:

ajax

http

https

I try to do ajax, my code written on a https site it request to non https, but the resources were blocked by Chrome.

            $.ajax({
                url : "http://example.com/non-https",
..
..

Previously in earlier version I don't have this issue. Must my ajax request target a https too? Or there is a better way to save that problem?

like image 997
Amy Johnson Avatar asked Jan 25 '15 07:01

Amy Johnson


People also ask

How do I fix blocked mixed content?

How to fix your website. The best strategy to avoid mixed content blocking is to serve all the content as HTTPS instead of HTTP. For your own domain, serve all content as HTTPS and fix your links. Often, the HTTPS version of the content already exists and this just requires adding an "s" to links - http:// to https://.


1 Answers

Just change the http:// in your url variable to //, so when the page is loaded with http, the ajax request would use the http protocol, if loaded with https, the ajax request protocol would be set by the browser to https. i.e, your code should look like:

           $.ajax({
                url : "//example.com/non-https",
..
..
like image 105
PalDev Avatar answered Oct 01 '22 06:10

PalDev