xmlhttprequest not working

J

jason.lucey

Hi,

I need some help figuring this out. I cannot get the xmlhttprequest
object to return responseXML or getAllResponseHeaders. responseText
works fine, but i'd rather use xPath than regular expressions to
populate some tables.

I'm using the XMLHttpRequest object for Mozilla and the
ActiveXObject("Msxml2.XMLHTTP") for IE.

Here is the javascript:

//script to load the xml doc using xmlhttprequest or xmlhttp
if(xDoc) {
xDoc.open("GET",url,false);
xDoc.setRequestHeader("Content-Type","text/xml");

if(window.ActiveXObject){
xDoc.send("");
} else {
xDoc.send(null);
}

if (xDoc.readyState==4) {
alert(xDoc.responseText); //works fine
var xHead;
xHead = xDoc.getAllResponseHeaders();
alert(xHead); //returns null
xDoc = xDoc.responseXML.xml;
alert(xDoc.length); //returns 0
} else {
alert("Error--readyState: " + xDoc.readyState);
}
}


Any help would be great.

thanks.
 
K

km0ti0n

xDoc = xDoc.responseXML.xml;

Only IE has the .xml property, also try accessing the documentElement
of xDoc.responseXML.

It might help if you show some of the xml that's beening returned. Is
it actually well formed XML.

Also if you want to use XPath Mozilla / FireFox doesn't have the
selectNodes / selectSingleNode that IE Has. This is my implymentation
of it :

http://km0ti0n.blunted.co.uk/mozXPath.xap

Hope that helps
 
J

jason.lucey

Well, I tried the documentElements property too, and that didn't work
either. here is some more fun. The status and statusText properties
don't return:

....
if (xDoc.readyState==4) {
alert(xDoc.statusText); //returns "unknown"
alert(xDoc.responseText); //works fine
....

also, I did have this code working in IE when I used the DomDocument3.0
active X object. however, in xmlhttp it doesn't work (well, the
responseText method works).

here is a node of the XML file. i haven't edited this since it worked
fine before:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?>
<?META http-equiv="Content-Type" content="text/xml"?>
<product>
<item>
<sSpec_Number>[deleted]</sSpec_Number>
<EPM_Product_Name>[deleted]</EPM_Product_Name>
<Architecture>[deleted]</Architecture>
<L2_Cache>512KB</L2_Cache>
<Clock__Speed>3</Clock__Speed>
<Front_Side_Bus_Speed>800</Front_Side_Bus_Speed>
<Other_Technologies>[deleted]Other_Technologies>
</item>
</product>

yeah, that selectNodes thing is a drag.

Thanks for your help.
 
K

km0ti0n

Indeed, Ian is right. You need to create a handler for the requests.
that you can resue time and time again. It's really simple to generate
a cross browser compatable one. Again there's a link to one on the url
I posted (XHConn) in the Acknolegments,
 
J

jason.lucey

Unfortunately, I cannot post the whole script. However, the piece that
I posted above is where the problem is. when I built the prototype
(which worked fine), I did it using new ActiveXObject(DomDocument3.0)
instead of new XMLHttpRequest (or new ActiveXObject(msxml2.XMLHTTP) and
they don't work the same at all, apparently. Since the implimentation
needs to be cross-browser, I'm kinda stuck.

hopefully converting the selectNodes xPath stuff to xmldom won't be so
frustrating.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top