How can I explicitly make an AJAX HTTPS GET request using jQuery? I am trying to do the following.
On an https page, I have a line with the code $.get(\"/resource\")
If the page you are on is an https page, and the page .get is trying to access is http, then that will not work due to same origin. However, you could just write out the ajax instead of short handing it with .get :)
$.ajax({
type: "GET",
url: "https://someurl"
});
Though I suppose to be fair, that is still a short of true javascript
I fixed the issue. It turned out that due to the way that our Django site was configured, I needed to add a trailing slash to resource in the AJAX request. Without the trailing the slash, Django would then redirect to the URL with the trailing slash using an HTTP request instead of an HTTPS request.
In short, I replaced $.get("/resource")
with $.get("/resource/")
.
Thank you. I really appreciate all of your help.
Just use RewriteRule in your .htaccess file with the specified protocol, for example:
RewriteCond %{REQUEST_URI} .+[^/]$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L,QSA]
Try setting the datatype to "jsonp", that's helped me in the past with cross-origin requests.
$.ajax({
url: "//www.site.com/resource"
dataType: "jsonp",
success: function(data) {
$(".demo-card").html(data);
}
});