Jump to content

Safari - XMLHttpRequest.responseXML returning null


SouthFresh

Recommended Posts

I've been banging my head against the wall for four days now and can't seem to figure this one out.

var XMLHttpRequestObject;var xmlDoc;var pathtoxml = "the path to my actual xml file";if (window.XMLHttpRequest){	console.log('create standard XHR');	XMLHttpRequestObject = new XMLHttpRequest();}else if (window.ActiveXObject) {		console.log('Not standard, using activex');	XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");}console.log('Check if XHR exists');if(XMLHttpRequestObject) {		console.log('XHR Exists, attempting GET');	XMLHttpRequestObject.open("GET", pathtoxml);	console.log('Assigning handler function for XHRs onreadystatechange');	XMLHttpRequestObject.onreadystatechange = function()	{		console.log('if XHRs readystate is 4 then do something but right now it is: ' + XMLHttpRequestObject.readyState);		if (XMLHttpRequestObject.readyState == 4) 		{			console.log('readystate is 4, attempt to assign responseXML to xmlDoc');			xmlDoc = XMLHttpRequestObject.responseXML;			console.log('xmlDoc has been assigned');									console.log('The response xml is: ' + XMLHttpRequestObject.responseXML);										console.log('The doctype is: ' + xmlDoc.doctype);		}		}	console.log('Initiate XHR.send');	XMLHttpRequestObject.send(null);			}

Sorry about all the console.logs that are in there, but it's been the only way for me to be able to narrow down where the issue is.The path to my xml is valid, and even returns the correct doctype in browsers that aren't Safari.Safari gets the correct stuff for responseText, but get's Null for responseXML.... what have I done wrong?Thanks!

Link to comment
Share on other sites

I can't be sure if this will help, but I was researching the problem and found this:http://radio.javaranch.com/pascarello/2006...8096122600.html

After answering the question a bunch of times in the past year, I found that the following questions will find the error 99% of the time:
  1. Did you set your content type to text/xml?
  2. Is your request actually making it to the server and back?
  3. When you alert/examine the responseText, do you see anything that does not belong?
  4. Open up the dynamic XML document in your browser directly. (Type the url into the browser. This may require you to hard code post parameters or build a test form.) The browser will tell you if your XML is not formatted correctly. Is it formatted correctly?

Link to comment
Share on other sites

I think I'd run in to the same post.1. The response comes through correctly in FF, the doctype and dtd are all in the xml response when I view the source.2. responseText works so I have to assume that the server is responding.3. Nothing appears to be missing or extra in the responseText4. I've saved the document and uploaded it to http://www.validome.org/xml/validate/ and it validates.I'm at a loss.

Link to comment
Share on other sites

Does this XML document have a .xml extension? And if it doesn't, did you add the header() with PHP?

header("Content-type: text/xml");

Link to comment
Share on other sites

Try to set validateOnParse to false to the response before actually getting it, i.e.

	XMLHttpRequestObject.responseXML.validateOnParse = false;	console.log('Initiate XHR.send');	XMLHttpRequestObject.send(null);

Safari may have a problem validating the XML file, and assumes invalid.If that too doesn't work, try to remove the DTD. This will force validation off, since there won't be anything to validate against.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...