473,587 Members | 2,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XMLHttp request : responseXML is null while Post-ing

I tried POSTing from XMLHttpRequest, i can get the XML right on server
but responseXML from server is coming null. I can see the XML right in
responseText. but responseXML is null. responseText to DOM conversion
also fails while the XML in responseText seems valid ..

-- here is the javascript code for sending ---
{
this.request.on readystatechang e = this.handleStat eChange;

if( this.request) {
this.request.op en("POST", url ,true);
this.request.se tRequestHeader( "Content-Type", "text/xml");

var markup = serialize(doc);
this.request.se nd(markup);
}
---
it works fine and I can get XML on server. but from server I write the
same XML back -
---
InputStream is = request.getInpu tStream();
Document doc = XMLUtils.load(i s, false);

response.setCha racterEncoding( "UTF-8");
response.setCon tentType("text/xml");

PrintWriter writer = response.getWri ter();
BufferedWriter bufWriter = new BufferedWriter( writer);

XMLUtils.printD ocument(doc, bufWriter);
bufWriter.newLi ne();

response.flushB uffer();
bufWriter.close ();
---
I can receive the XML document right in responseText but responseXML is
null. cant make out whats happening here..

----
function processReqChang e()
{
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
alert(req.respo nseText);
handler.handle( req.resposeXML) ; // req.responseXML is NULL
HERE
} else {
alert("There was a problem retrieving the XML data:\n" +
req.statusText) ;
}
}
}
----

Jul 23 '05 #1
4 13345


Sanjay Dahiya wrote:

this.request.on readystatechang e = this.handleStat eChange;

if( this.request) {
this.request.op en("POST", url ,true);
this.request.se tRequestHeader( "Content-Type", "text/xml");
I would set onreadystatecha nge each time after the open call so move the
this.request.on readystatechang e = this.handleStat eChange;
down here after the open call.
var markup = serialize(doc);
this.request.se nd(markup);
}
---
it works fine and I can get XML on server. but from server I write the
same XML back -
---
InputStream is = request.getInpu tStream();
Document doc = XMLUtils.load(i s, false);

response.setCha racterEncoding( "UTF-8");
response.setCon tentType("text/xml");

PrintWriter writer = response.getWri ter();
BufferedWriter bufWriter = new BufferedWriter( writer);

XMLUtils.printD ocument(doc, bufWriter);
bufWriter.newLi ne();

response.flushB uffer();
bufWriter.close ();
---
I can receive the XML document right in responseText but responseXML is
null. cant make out whats happening here..

----
function processReqChang e()
{
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
alert(req.respo nseText);
handler.handle( req.resposeXML) ; // req.responseXML is NULL
HERE


Could you check the response headers e.g.
alert(req.getAl lResponseHeader s())
to the see the content type header that is sent?
And are you sure the markup sent is well-formed?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
thanks Martin,
I tried it, doesnt seem to work for me, yes the markup is well formed,
i tried a very small example which fails. here are the headers and
markup that i get on client (after POST). can "chunked" encoding cause
problem, i googled for it and didnt find anything useful ..

---header --
Content-Type: text/xml;charset=UTF-8
Transfer-encoding: chunked
---

-- markup from "request.respon seText" --
<?xml version="1.0" encoding="UTF-8"?>
<root><child>Da ta</child></root>

Jul 23 '05 #3


Sanjay Dahiya wrote:
yes the markup is well formed,
i tried a very small example which fails. here are the headers and
markup that i get on client (after POST). can "chunked" encoding cause
problem, i googled for it and didnt find anything useful ..

---header --
Content-Type: text/xml;charset=UTF-8
Transfer-encoding: chunked
---


The definition is here in the HTTP 1.1 specification
<http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3. 6>

Which browser are you using, is that a Mozilla browser?
You seem to use Java on the server, I don't know how to get your servlet
or JSP not to use Transfer-encoding: chunked but maybe you can switch
that off and try to see whether it improves things.
As far as I understand it any user agent supporting HTTP 1.1 should be
able to deal with Transfer-encoding: chunked but perhaps there is a bug
related to that.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4
I tried it on both IE6 and Firefox 1.0.2, yes I am using tomcat. will
try to switch chunked off .. and leave a msg if that works.
thanks

Jul 23 '05 #5

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

Similar topics

3
3087
by: Mark | last post by:
Hi all i was just wondering if you help. I have to send a cgi request to a company using xmlhttp request. They reply back with a line of info but when you view the internet explorer source code you see the XML format. I was just wonder if anyone could help me save the xml format to a xml file. I woul like to show you my code but there is to much confidential information about the company.
2
2517
by: mikeyjudkins | last post by:
Ive been banging my head on the wall for hours with this one, hopefully someone will know what Im doing wrong here :\ The Goal: I have an xml file that is generated on the fly via JSP which I want to load into a Microsoft.XMLHTTP ActiveX object and manipulate via javascript on the client side. Data is retreived from the server at the request of the javascript without having to reload the page. The Problem:
1
1324
by: Dave H | last post by:
First.. What object (on the client) should I be using these days? var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); or var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); or maybe something different?
0
2740
by: SushiSean | last post by:
When executing the xmlhttp.send function to request shipper for available shipments (I send xml as string and receive result xml): XMLHTTP xmlhttp = new XMLHTTP(); xmlhttp.open("POST", "https://gateway.fedex.com:443/GatewayDC", false, "", ""); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(strXML);
2
10628
by: ashish ranjan | last post by:
Hi there, I want to fetch data from database ,convert it in xml then send this xml from server.In Javascript file i am trying to parse it and bind these data to some control like textbox in client page.But the xmlHttp.responseXML.documentElement returned from server is showing null: I m using .Net,C#,(Ajax) ******************************************************** code snippet: serverPage.aspx.cs...
4
8269
by: sirjohnofthewest | last post by:
If I possessed the power to sway the mind of every user in the world to delete all forms of Internet Explorer I would die a happy man. Hi guys, I frequently visit this site to get answers to my problems and this one is really getting to me... I have a page that allows you to Browse Authors. There are three drop down boxes that auto-populate via AJAX. I have a file which it calls and returns the dynamically built XML file in the boxes...
3
19016
by: JMcCrillis | last post by:
I've implemented a FileUpload servlet using AJAX and JS. It appears to be working well but for one issue. I used XMLHTTP so I could intercept the response in Javascript and write it out to a field on my webpage. I get back that my readyState is 4 and my status is 200 and status text is "OK", but my responseText is always empty. Both on FireFox and IE7, so it must be something I'm doing (wrong). I've also set up an IFRAME to redirect the...
1
3079
by: Sand Yaah | last post by:
i went thru a discussion put by eros and helped out by dmjpros. d questions asked were right and i tried each but there was no problem there. my code returns null in xmlHttp.responseXML and xmlHttp.responseText returns nothing. My Code: function commoPrice() { var cid = document.kerala.commodities.value; if(cid ==0)
2
12452
by: trpost | last post by:
Is it possible to execute javascript as passed in xmlHttp.responseText Here is what I am doing: search.js var xmlHttp xmlHttp=GetXmlHttpObject() var url="search.php" xmlHttp.onreadystatechange=stateChanged
0
8219
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
8349
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7978
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8221
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
6629
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...
0
5395
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3845
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...
1
2364
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
1455
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.