I am done developing my first hybrid app. It runs smoothly in localhost. But when I tried to make it live, I got this error.
XMLHttpRequest cannot load https://www.example.com/app/login.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 500.
Why is this happening?
Here is my sample set up on my ajax request:
$.ajax({
type: "POST",
url: "https://www.example.com/app/login.php",
crossDomain: true,
dataType: 'json',
data: $.trim(frm.serialize()),
timeout: 10000,
beforeSend: function() {
$('#loader').css({
display: "block"
});
}
Then on my php server code:
<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
header('HTTP/1.1 200 OK');
{
//more code here..
echo json_encode($result_array);
}
So as you can see I already added a header Access-Control-Allow-Origin: * but it seems doesn't work. What do I need to know to make this error gone? Or what should the possible problem of it?
Update: In firefox this is the console log error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.example/app/login.php. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)
Any help? I'm using intel xdk in building my app.
I don't think your problem has anything to do with access-control
From your error:
The response had HTTP status code 500
Suggests that your application crashed. As a result, the Access-Control-Allow-Origin header was never properly set. When access-control is the problem, the browser (Firefox anyway) shows status code 401 Unauthorized, not 500 server error
Look in your error logs for the cause of the crash. Also try disabling .htaccess and see if the error persists because broken rules/config are a common cause of crashes
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