Forcing AJAX call to be HTTPS from HTTPS Page

KirisuteRanza picture KirisuteRanza · Feb 2, 2015 · Viewed 7.8k times · Source

Currently making an AJAX call from a HTTPS jsp to call in data from another jsp page. We are however getting a Mixed content issue:

Mixed Content: The page at 'https://etc/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://etc/path/to/other/page.jsp'. This request has been blocked; the content must be served over HTTPS.

How do you force an AJAX call to call over HTTPS?

The AJAX call looks like the following:

var url = "/path/to/other/page.jsp";

$.ajax({                                                            
    type: "POST",
    url: url,
    data: {data: data},
    dataType: "html",
    timeout: 4000, 
    success: function(html) {
        /* Code on Success */
        }
    },
    error: function(request, status, error) {
         /* Code on Failure
    }   
});

I could understand if I was trying to make a call from HTTPS to HTTP, but I don't want to. I want to force this to call the JSP using HTTPS is all, so I can avoid the Mixed Content issue.

Thank you in advance!

/* EDIT */

Interestingly I put in the variable URL an absolute path:

var url = "https://etc/path/to/other/page.jsp";

And I got the same issue. Something is forcing this AJAX call to be HTTP?

Answer

Josephy Besim picture Josephy Besim · Feb 2, 2015

Try use another extension or use like folder with .htaccess etc. like this

var url = "https://etc/path/to/other/page/";