Hello,
I am working on a site and have 3 different branches. Typical dev->stage->production situation.
All 3 run on 3 different urls:
prod: http://www.domain.com
stage: http://www.domain.com/stage
So i am trying to have universal code that runs on all 3 without any modification to file paths.
To achieve that i just have base_path
var set, to whatever CodeIgniter installation is configured with for this particular branch.
var base_url = "<?=base_url();?>"; // This sets base_url accordingly.
$.post(base_url + 'login/ajaxLogin', { // See note below
login_email: $('#login_email').val(),
login_pass: $('#login_pass').val(),
},
function(data) {
if(data == 'true') {
window.location.href = base_url;
} else {
$('h2').replaceWith('<h2 style="color:#b81900;">Login Failed</h2>');
return false;
}
});
Above code works fine in Chrome. But it does not work in Safari and Firefox.
In Firefox it fails silently, and in Safari I get "Unable to load resource: cancelled"
NOTE: If i remove base_url
and just set script path to /login/ajaxLogin
, /dev/login/ajaxLogin
or /stage/login/ajaxLogin
everything works perfectly.
It appears that I may be hitting Cross-domain scripting restriction, but I am not sure why?
Yes, I am familiar with Same Origin Policy and yes, I have seen this on jQuery's site:
Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.
If a request with
jQuery.post()
returns an error code, it will fail silently unless the script has also called the global.ajaxError()
method.
None of the above applies in my case as I am staying within my domain, so I am not entirely sure what is going on, but i would really like to find a workaround for this issue.