Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax GET request over HTTPS

How can I send an ajax GET request over HTTPS?

$.get throws this:

XMLHttpRequest cannot load https://********. Origin null is not allowed by Access-Control-Allow-Origin. 

Is there another way or some workaround to get this working?

If I navigate to the url with Chrome I'm able to get the response. I see no reason why it shouldn't work work over an ajax request.

like image 566
jviotti Avatar asked Mar 13 '13 02:03

jviotti


People also ask

Does AJAX work with https?

You cannot make an AJAX request to an https page if you are currently in http because of the Same Origin Policy. The host, port and scheme (protocol) must be the same in order for the AJAX request to work.

How to use GET and post in AJAX?

GET is basically used for just getting (retrieving) some data from the server. Note: The GET method may return cached data. POST can also be used to get some data from the server. However, the POST method NEVER caches data, and is often used to send data along with the request.


1 Answers

You cannot make an AJAX request to an https page if you are currently in http because of the Same Origin Policy.

The host, port and scheme (protocol) must be the same in order for the AJAX request to work.

You can either make sure that the originating page is on the same host and scheme or implement CORS (cross-origin resource sharing) on the target domain to permit this particular request.

like image 111
Andrew Moore Avatar answered Oct 19 '22 03:10

Andrew Moore