473,804 Members | 3,722 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 6434
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
1939
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 12345 (for example) on IE. There is no output in Opera either but I guess that's just one of those...
2
6539
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 servers are under my control, however. Is there a way to get around this
20
2697
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 webpage with a slightly modify version. Basically I have two questions: (1) Do I need to set my...
3
1889
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
2193
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 with in it's body the following lines <script type="text/javascript" language="javascript">
13
11509
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 that I've programmed into it. When I check the readyState it only returns 0 and never goes through the...
6
3812
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 for your help.
1
4035
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 using it are amazing. There are too many PHP programmers avoiding any
20
4048
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 compeltely overwrite the original page. I want it to update the existing page by loading within a <div>...
6
2307
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 ActiveXObject("Microsoft.XMLHTTP");
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9569
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10558
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9130
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2975
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.