Jump to content

IE Failing to Read XML


JRI_Work

Recommended Posts

I have a stand alone web page that needs to be able to run w/o a web server (i.e. you click on the HTML file and it just runs). It is intended to be given away to anyone who wants it and thus needs to be usable by non-computer people.This web page uses several XML files like a database to extract key pieces of data.This web page works perfectly under all the major browsers except IE. When it tries to access the 1st XML file, IE gives the standard warning at the top of the browser: "To help protect your security, Internet Explorer has restricted this webpage from running scripts or ActiveX controls that could access your computer. Click here for options...". Interestingly, it displays the web page w/o any of the xml data.I "click here for options..." and choose the "Allow blocked content" option. This gives the "... Are you sure..." message, and I click "yes". The web page reruns (I think) but gives a little error icon in the lower left.I click on it to see the errors, and I am getting an "Access denied" error at line 30 (part of my loadXMLString function used to open an XML file).

function loadXMLString(xmlName) {	if (window.XMLHttpRequest) {		xhttp=new XMLHttpRequest();	} else {		// Internet Explorer 5/6		xhttp=new ActiveXObject("Microsoft.XMLHTTP");	}	xhttp.open("GET", xmlName, false);   <--- line 30 - failing	xhttp.send("");	return xhttp.responseXML;}

This function is called 4 times as the web page is initially loaded (once for each of the XML files).I got the basis of this code from w3schools XML Parser (which is where I go to get most help).The only difference I see between my function and the example given at w3schools is that I am passing the file name vs. the example has it hardcoded. I would not think this is a problem, esp. since the other browsers all work.What am I missing or doing wrong?

Link to comment
Share on other sites

Where is the XML file you are trying to open? You can only fetch files from the same domain using AJAX.

Link to comment
Share on other sites

Where is the XML file you are trying to open? You can only fetch files from the same domain using AJAX.
Everything is in the same directory except for some simple images that are in a sub-directory. That is why this should be so easy to give away to anyone. Just plop it on your computer, run from a thumb drive, or whatever.
Link to comment
Share on other sites

The code is intended to be executed in the security context of a web server, not a local file. Local files have tighter security settings in IE than files served from a web server.This is an example of an ajax script which will work to load a local file when run in Firefox or Opera, but it does not work in IE with the default security settings. This script loads a document called alt.html and puts the content into a text area and div.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><script type="text/javascript" language="javascript">  function sendRequest(url,callback,postData) {	var req = createXMLHTTPObject();	if (!req) {	  alert('no ajax object');	  return;	}	var method = (postData) ? "POST" : "GET";	req.open(method,url,true);	req.setRequestHeader('User-Agent','XMLHTTP/1.0');	if (postData)	  req.setRequestHeader('Content-type','application/x-www-form-urlencoded');	req.onreadystatechange = function () {	  if (req.readyState != 4) return;	  /*	  if (req.status != 200 && req.status != 304) {		alert('HTTP error ' + req.status);		return;	  }	  */	  callback(req);	}	if (req.readyState == 4) return;	req.send(postData);  }    var XMLHttpFactories = [	  function () {return new XMLHttpRequest()},	  function () {return new ActiveXObject("Msxml2.XMLHTTP")},	  function () {return new ActiveXObject("Msxml3.XMLHTTP")},	  function () {return new ActiveXObject("Microsoft.XMLHTTP")}  ];    function createXMLHTTPObject() {	var xmlhttp = false;	for (var i=0;i<XMLHttpFactories.length;i++) {	  try {		xmlhttp = XMLHttpFactories[i]();	  }	  catch (e) {		continue;	  }	  break;	}	return xmlhttp;  }  function get() {	sendRequest('alt.html', function(resp) {document.getElementById('content').innerHTML = resp.responseText; document.getElementById('content2').innerHTML = resp.responseText;});  }</script></head><body>  <textarea id="content"></textarea>  <input type="button" onclick="get();" value="Submit" />  <div id="content2"></div></body></html>

If you wanted that to work in IE, you would need to change the security settings for the local zone. Ajax is intended to work with a web server, not a file that you double-click on to open in a browser. Notice that the code to send the request has the part where it checks the server response status commented out, because the status will always be 0 due to the fact that there's not a web server involved in sending the response back.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...