473,555 Members | 2,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xmlhttprequest not working

Hi,

I need some help figuring this out. I cannot get the xmlhttprequest
object to return responseXML or getAllResponseH eaders. 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.setRequest Header("Content-Type","text/xml");

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

if (xDoc.readyStat e==4) {
alert(xDoc.resp onseText); //works fine
var xHead;
xHead = xDoc.getAllResp onseHeaders();
alert(xHead); //returns null
xDoc = xDoc.responseXM L.xml;
alert(xDoc.leng th); //returns 0
} else {
alert("Error--readyState: " + xDoc.readyState );
}
}
Any help would be great.

thanks.

Sep 21 '05 #1
8 6421
xDoc = xDoc.responseXM L.xml;


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

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 / selectSingleNod e that IE Has. This is my implymentation
of it :

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

Hope that helps

Sep 21 '05 #2
ja*********@gma il.com wrote:
Hi,

I need some help figuring this out. I cannot get the xmlhttprequest
object to return responseXML or getAllResponseH eaders. 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.setRequest Header("Content-Type","text/xml");

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

if (xDoc.readyStat e==4) {
alert(xDoc.resp onseText); //works fine
var xHead;
xHead = xDoc.getAllResp onseHeaders();
alert(xHead); //returns null
xDoc = xDoc.responseXM L.xml;
alert(xDoc.leng th); //returns 0
} else {
alert("Error--readyState: " + xDoc.readyState );
}
}


I'm guessing these are just code fragments, as xDoc.readyState would
probably not make it to 4 in time to get to the part that //works .
(xDoc.onreadyst atechange)

I'm staring at this waiting for something to jump out at me , but
I'm leaning towards the thought that there may be more to this problem
than what we can see here

I myself have already made this journey, and the result was that
I created a little library jsXMLlib.js that merged the functionality
of XMLDOM and XMLHTTP into a little javascript class. Declaring a new
connection goes like this new DCxml(yourURL,y ourCallbackFunc tion)
and as a bonus , I can open many connections at the same time.

Perhaps if you had a sample URL , where we could see what your trying to
do in it's totality.

--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Sep 21 '05 #3
Well, I tried the documentElement s property too, and that didn't work
either. here is some more fun. The status and statusText properties
don't return:

....
if (xDoc.readyStat e==4) {
alert(xDoc.stat usText); //returns "unknown"
alert(xDoc.resp onseText); //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_Na me>[deleted]</EPM_Product_Nam e>
<Architecture >[deleted]</Architecture>
<L2_Cache>512KB </L2_Cache>
<Clock__Speed>3 </Clock__Speed>
<Front_Side_Bus _Speed>800</Front_Side_Bus_ Speed>
<Other_Technolo gies>[deleted]Other_Technolog ies>
</item>
</product>

yeah, that selectNodes thing is a drag.

Thanks for your help.

km0ti0n wrote:
xDoc = xDoc.responseXM L.xml;


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

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 / selectSingleNod e that IE Has. This is my implymentation
of it :

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

Hope that helps


Sep 21 '05 #4
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,

Sep 21 '05 #5
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(D omDocument3.0)
instead of new XMLHttpRequest (or new ActiveXObject(m sxml2.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.

Sep 21 '05 #6
Use try / catch to test which one of the objects you need to create.

var xhr;
try{ xhr = new ActiveXObject(" Msxml2.XMLHTTP" ); }
catch (e){/*FF fails so use*/ xhr = XMLHttpRequest( );}

But theres a link to a fully functioning example off
http://km0ti0n.blunted.co.uk/mozXPath.xap go to the bottom of the page
and click XHConn.

Sep 21 '05 #7
ja*********@gma il.com wrote:
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(D omDocument3.0)
instead of new XMLHttpRequest (or new ActiveXObject(m sxml2.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.


If you go here http://www.drclue.net/projects/jsDHTMLlib/
and download the jsDHTMLlib.zip, you'll find the jsXMLlib.js
contained in the zip.

It works on IE,NS,*Opera*,F irefox, and just about anything else that
has the support or a way to fake it.

If nothing else , you can look over what I did and clone the
parts you neeed.
--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Sep 21 '05 #8
ja*********@gma il.com wrote:
I need some help figuring this out. I cannot get the xmlhttprequest
object to return responseXML or getAllResponseH eaders.
It appears that you create the object and send the request, but you don't
want for it to come back.
if (xDoc.readyStat e==4) {


Rather than this being immediately after the send call, you need to wait for
your object to trigger an onreadystate change event, then check where it's
at.

To simplify the process, you may want to consider using a generalized lib
like the one found at my Ajaxtoolbox.com site (see sig).

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Sep 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1929
by: Dominic Myers | last post by:
Hi there, I'm playing with XMLHttpRequest and followed the article by Bill Bercik at http://www.webpasties.com/xmlHttpRequest/... I'm having problems getting the last two steps to work though. The page that I'm working on is here: http://camshag.co.uk/svg/XMLHttpRequest/. It works fine in Firefox but there is no output for the zip code...
2
6526
by: dx27s | last post by:
Hi all, I'm working with the XMLHttpRequest object. I receive the following error message: "Permission denied to call method XMLHttpRequest.open" This occurs in Firefox only. IE works fine. From my research so far, it seems like this is a security issue related to the fact that I am trying to access a url on a second server. Both...
20
2651
by: chris.schwalm | last post by:
This is part II of this <a href="http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/cd54951e0ea277de/639c67f2f7cadb1f?tvc=2&q=Simple+HTML+read%2Fwrite+question#639c67f2f7cadb1f"> post</a>. I am creating a java script that bascially reads a webpage - forwards it to an external program/parser/servlet - then overwrites the...
3
1874
by: VK | last post by:
The Web API Working Group has released the First Public Working Draft of The XMLHttpRequest Object. <http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/> P.S. Finally some good movement after this over-extended "there will be no XHTML" groggy state.
1
2175
by: 4levels | last post by:
Dear Folks, I stumbled upon a strange behaviour of the XMLHttpRequest.. Maybe I'm just not well informed enough about its possibilities, so could someone please confirm my question? When I put plain javscript in a file that is read-in through a XMLHttpRequest-object, it's like it is totally ignored. Eg. I have the file ajax_include.html...
13
11466
by: TLaufenberg | last post by:
I'm new to Javascript programming and I've run into a bit of a snag with making an XMLHttpRequest in the Safari browser. Actually, the request doesn't work in Firefox either but only when I use a Mac computer. IE and FireFox on a Windows based system works just fine. The problem I am having is that the XMLHttpRequest doesn't open the site...
6
3785
by: eulaersivan | last post by:
I would like to use the xmlhttprequest-object to send an http request to my server. The http request is used to switch the light on through home automation. However it's not working, and I can't find the problem. Could it be that the apache-server is located on 192.168.0.21 and that the http request is sent to 192.168.0.21:8080? Thanks...
1
4017
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest technology is implemented on more sites now than ever. Compatibility is no longer an issue (IE, Mozilla and Opera all support it), and the benefits to...
20
4009
RMWChaos
by: RMWChaos | last post by:
Currently testing in: WinVista / IE7 I have been working on getting xmlhttprequest going for weeks now. I have finally gotten a semi-working script going. Pulling up text or xml files works great and populates into the webpage; however, executing javascript has a few problems: 1. Opens on a blank page, but not a new page. It appears to...
6
2297
by: Patrick Nolan | last post by:
I'm working on cross-platform portability of some javascript. My Macintosh testing platform is rather old. It has Safari 1.3.2 and Internet Explorer 5.2. I got Safari working, but now IE is causing trouble. It chokes on this: if (window.XMLHttpRequest) nameReq = new XMLHttpRequest(); else if (window.ActiveXObject) nameReq = new...
0
7542
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7824
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8060
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5452
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5170
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2034
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1156
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.