Error for Cross Domain AJAX
I was running into an issue at my work. When I clicked a certain link that was supposed to activate an AJAX portion of the site, in Firefox it wouldn’t work and in IE I would get:
This page is accessing information that is not under its control. This is a security risk. Do you want to continue?
The problem was caused by doing an http.open on a domain that was other than that which the script was being run. This wasn’t my intention, so to avoid this issue, I added some server-side host checking, and inserted it into the javascript where necessary:
function getSite(){
var host=<?php echo "'http://".$_SERVER["HTTP_HOST"]."'"; ?>;
if(host != 'http://host1'){
host+='/subdir';
}
return host;
}
I’m sure there’s an easier way, but this worked for me to utilize a “public” and “private” copy of this script without manually editing that value.
