I am trying to insert/hide a table in my page using AJAX.

Works perfectly in Firefox. IE 7 gives me "Error: Access is denied" for the following line:

xmlReq.open("GET", url, true);

Any ideas why?

Recommended Answers

All 9 Replies

There is insufficient information here to help you out. I recently created an AJAX code that would dynamically create a table and populate its table data. Could that be what you are trying to accomplish.

i have the table save in HTML format in a separate file.

i'm using an xmlHttpRequest object in firefox to retrieve it and doing this:

div.innerHTML = xmlReq.responseText;

like i said, works in Firefox but not IE.

and yes, in the IE version im using the ActiveX object instead of the standard.

Did u get the responseText in IE ?
Can u alert the responseText in IE

It doesn't ever get that far. It returns the "Access denied error" on:

xmlReq.open("GET", url, true);

chances are your AJAX script is breaking down before you even get to the response text. what I would recommand is to test the script by inserting a series of alerts up to the point where you are expecting certain result. For example, when I test my AJAX code, I checked to see if my object is created by alerting the object. If it is created, then I test the readystate to see if the value is equal to 4 and so on.

can you post your entire AJAX code in here so we can look at it?

//Quick check for AJAX functionality. Copied from w3schools.com
function MakeXMLReq()
{
  var xmlHttp = null;

  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer 6+
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      //For IE 5.5 Users
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }

  return xmlHttp;
}

function getTable(info)
{
  var tableDiv = document.getElementById("externalTable");
  var xmlReq = MakeXMLReq();

  xmlReq.onreadystatechange = function()
  {
    if (xmlReq.state = 4)
    {
      try
      {
        tableDiv.innerHTML = xmlReq.responseText;
        tableDiv.innerHTML += "<br /> <a href = \"#top\" onclick = \"hideDiv()\" class = \"internal text-center\">Hide Table</a>";
        tableDiv.style.display = "inline";
      }
      catch (ex)
      {
        alert("Error: Unable to display AJAX retrieved table.");
        return;
      }
    }
  }
  
  var url = info + "_table.html";
  xmlReq.open("GET", url, true);
  xmlReq.send(null);
}

One problem that I noticed right away is that your getTable() method is evaluating the the state of xmlReq within the if statement but you are assigning it a value of 4 rather than evaluating it to 4. So make this correction and try to run the script again.

if(xmlReq.state == 4)

Second, I am not sure that you can use the word state instead of readystate, so you might want to experiment to see which on works.

While you are working on the aforementioned fix, I'll try to see what else is wrong with the code.

I think I found the problem. Seems that I have to be running the page as an HTTP page instead of a local page. Firefox doesn't care but it looks like IE doesn't let local pages access HTTP services.

I hate IE...

> It doesn't ever get that far. It returns the "Access denied error" on:

Are you trying to make cross domain calls? What kind of URL are you using in your call anyways? Does it belong to your domain?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.