Lately, we have been successfully utilizing Ajax calls within our applications for URLs that are part of the server domain. However, when attempting to make an Ajax call to a URL on the web, it consistently fails without providing a clear error message. Despite conducting thorough research online with the information available, I've yet to uncover a reasonable cause or solution to this perplexing issue.
Here is a simplified version of the Ajax call code snippet:
var url = "http://www.google.com";
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert('done');
}
};
xmlhttp.open("GET",url,true);
xmlhttp.send();
The problem arises specifically when the URL is from an outside domain like Google, resulting in various failures across different browsers.
In IE9, 'Javascript error: Access denied' occurs along with 'could not complete the operation due to error c00c023f' as the status.
On Chrome and FF, although no log errors are displayed, the status remains at 0.
Unfortunately, regardless of the browser, the Ajax call always ends in failure.
What could be causing this peculiar issue? It seems unlikely to be a network problem since accessing the Google URL directly via the browser works just fine. What might be preventing the Ajax call from functioning properly within the browser?
Best Regards, Vijay.K