Whenever I create an jQuery.ajax
request it works fine when the URL uses the HTTP protocol. But when I send the same request to the HTTPs server, it is sent without the header [HTTP_X_REQUESTED_WITH: XMLHttpRequest
]. Thus the server has no way of knowing that this is an AJAX request!
I've tried:
beforeSend
CrossDomain:true
Note: There are no cross-domain issues, the request is valid and handled, but not as AJAX.
This issue happens when the current URL is http but the requested URL is on the same domain but uses HTTPS. http://example.com/home will use AJAX POST to post to
I tried Kishor's approach, but the header didn't get sent. I modified it, setting the header like this:
$.ajax {
beforeSend: function(jqXHR, settings) {
jqXHR.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
},
...
};
I'm using jQuery 1.8.2.
I got the same issue for doing same stuff between http and https.
I have researched this and it is cross domain issue. Please try JSONP with call back function for doing the stuff, and the most important thing the server side page you are using for doing curl has to set some headers for allowing http to https connection. These are below:
header("Access-Control-Allow-Origin: your https url");
header("Access-Control-Allow-Methods: POST, GET");
header("Access-Control-Max-Age: 1728000");
header("Access-Control-Allow-Headers: Content-Type, Connection, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");
header("Connection: close");
$.ajax {
...
...
beforeSend : function(jqXHR, settings) {
jqXHR.setRequestHeader("HTTP_X_REQUESTED_WITH", "XmlHttpRequest"
}
...
...
}
Hope this one helps :D
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