My site uses http and https protocol; it doesn't affect the content. My site uses jQuery ajax calls, which fills some areas on the page, too.
Now, I would like to do all ajax calls over https. (please dont ask me why :)) When I am on a page with https protocol, ajax requests are working. When I'm on a page with http protocol, I get a javascript error: Access to restricted URI denied
I know that this is a cross domain problem (in fact, it's a cross protocol problem), and I know that I should use the same protocol in ajax calls as on the current page.
Still, I want to all ajax calls to be https, and call them on a page that was served over http. Is there any workaround to achieve this (some json/proxy solution?), or is it simply impossible?
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't. Browsers prevents this by default as otherwise it would be insecure to allow it. The remote server must have a valid SSL certificate and use HTTPS.
With both AJAX and non-AJAX the browser sends HTTP requests and receives HTTP responses from the web server. Deference between an AJAX request and a non-AJAX request is that, AJAX requests: work in the background seamlessly, and. don't make the pages to reload every time a response is received.
jQuery - AJAX get() and post() Methods. The jQuery get() and post() methods are used to request data from the server with an HTTP GET or POST request.
Add the Access-Control-Allow-Origin header from the server
Access-Control-Allow-Origin: https://www.mysite.com
http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing
Try JSONP.
most JS libraries make it just as easy as other AJAX calls, but internally use an iframe to do the query.
if you're not using JSON for your payload, then you'll have to roll your own mechanism around the iframe.
personally, i'd just redirect form the http:// page to the https:// one
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With