Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery AJAX on HTTPS - Resource failed to load

I have own API at http(s)://www.api.domain.com (on HTTPS there is RapidSSL installed).

If I acccess that URL via browser I get

{"error":{"code":404,"message":"Invalid API version."}}

which is fine.

If I access https://www.api.domain.com/v1/auth I get

{"error":{"code":404,"message":"Missing authorization header."}}

which is also OK (sign that API works OK on SSL).

I have jQuery AJAX call to that API from other domain. If I make a call without SSL (http://www.api.domain.com/v1/auth) everything is working OK (I'm sending authorization headers and all other necessary stuff) and I'm getting responses. If I try to access to the same thing but with SSL (https://www.api.domain.com/v1/auth) I get OPTIONS https://www.api.domain.com/v1/auth Resource failed to load.

Also, CORS is working. On PHP side I have

if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Headers: Authorization, x-domain-accesskey, X-Requested-With');
    exit;
}

so it's working, but only without SSL. In chrome I see one OPTIONS request and then GET/POST/whatever I requested. It's working just fine.

But when I try to move on HTTPS,

Resource failed to load

On Network tab I have only this (not sure why on the first image is showing OPTIONS, but on the details POST)

enter image description here

enter image description here

enter image description here

and then just...stops? In jQuery it stops on line

xhr.send( ( s.hasContent && s.data ) || null );

$.ajax is normal (don't have crossDomain: true, dataType: jsonp or something else).

Ideas?

like image 725
svenkapudija Avatar asked Jan 20 '26 22:01

svenkapudija


1 Answers

make the page youre sending the https ajax request from render in https and it should work fine for you.

like image 104
Rooster Avatar answered Jan 23 '26 11:01

Rooster