If I use the following Javascript to power my small AJAX site.... it keeps giving this error:
uncaught exception: Permission denied to call method XMLHttpRequest.open
So, the code I'm using is this:
var req=null;
var console=null;
var rpg=null;
function loading(state)
{
document.getElementById('loading').style.visibility = (state == true) ? 'visible' : 'hidden';
}
function sendRequest(page,params,HttpMethod)
{
loading(true);
rpg = page;
if(!HttpMethod)
{
HtttpMethod = "POST";
}
req = initXMLHTTPRequest();
if(req)
{
var url = 'http://www.patternet.com/scripts/pages.php?p=' + page;
req.onreadystatechange = onReadyState;
req.open(HttpMethod,url,true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(params);
}
else
{
toConsole('Unable to complete XMLHTTPRequest call.');
}
}
function initXMLHTTPRequest()
{
var xRequest = null;
if(window.XMLHttpRequest)
{
xRequest = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
try
{
xRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
xRequest = false;
}
}
}
return xRequest;
}
function onReadyState()
{
var ready = req.readyState;
var data = null;
if(ready == 4)
{
data = req.responseXML;
}
else
{
data = "loading";
}
toConsole(data);
}
function toConsole(data)
{
if(data != "loading" && reg.readyState == 4)
{
document.title = data.getElementsByTagName('title')[0].childNodes[0].nodeValue;
document.getElementById('mainbody').innerHTML = data.getElementsByTagName('content')[0].childNodes[0].nodeValue;
loading(false);
}
else
{
document.title = 'Patterson Web Services :: Error On Page';
content.innerHTML = 'Sorry, there was an error retrieving the information from the server. The last request was: <br />' + req.readyState;
loading(false);
}
}
window.onload=function()
{
loading(false);
console = document.getElementById('mainbody');
sendRequest('home');
}
So the line that keeps erroring is this one:
req.open(HttpMethod,url,true);
Anyone have any clue as to why it's erroring?