This request has been blocked; the content must be

2020-03-19 01:49发布

问题:

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?

回答1:

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",
..
..


标签: ajax http https