Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > xmlhttprequest not working

Reply
Thread Tools

xmlhttprequest not working

 
 
jason.lucey@gmail.com
Guest
Posts: n/a
 
      09-21-2005
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.

 
Reply With Quote
 
 
 
 
km0ti0n
Guest
Posts: n/a
 
      09-21-2005

> 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

 
Reply With Quote
 
 
 
 
jason.lucey@gmail.com
Guest
Posts: n/a
 
      09-21-2005
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


 
Reply With Quote
 
km0ti0n
Guest
Posts: n/a
 
      09-21-2005
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,

 
Reply With Quote
 
jason.lucey@gmail.com
Guest
Posts: n/a
 
      09-21-2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xmlHttpRequest is not working eulaersivan@yahoo.com Javascript 6 01-21-2007 09:38 AM
inline javascript not working while reading from XMLHttpRequest object 4levels@gmail.com Javascript 1 06-09-2006 02:35 PM
W3C working draft of XMLHttpRequest is released VK Javascript 3 04-06-2006 09:32 AM
XMLHttpRequest not working as expected Unknown User Javascript 2 02-08-2005 04:42 PM
XMLHTTPRequest with Xpath is not working =?Utf-8?B?QnJhdm8=?= ASP .Net 0 04-01-2004 08:56 PM



Advertisments