Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   xmlhttprequest not working (http://www.velocityreviews.com/forums/t920302-xmlhttprequest-not-working.html)

jason.lucey@gmail.com 09-21-2005 08:45 PM

xmlhttprequest not working
 
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.


km0ti0n 09-21-2005 10:06 PM

Re: xmlhttprequest not working
 

> 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


jason.lucey@gmail.com 09-21-2005 10:19 PM

Re: xmlhttprequest not working
 
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.



km0ti0n wrote:
> > 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



km0ti0n 09-21-2005 10:22 PM

Re: xmlhttprequest not working
 
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,


jason.lucey@gmail.com 09-21-2005 10:28 PM

Re: xmlhttprequest not working
 
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.



All times are GMT. The time now is 06:26 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57