473,466 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XMLHttpRequest Question

I have been searching all over the place for a good full explanation of
what can be passed back and forth using the XMLHttpRequest Object.

http://jibbering.com/2002/4/httprequest.html

That site has a good intro on what it can do to receive one piece of
information back. However is it possible to pass more? This object is
supposed to be able to pass a full DOM tree, but I haven't found any specs
on what the tree should be sent as from the server or how to parse it
after I receive it.
Jul 23 '05 #1
8 3264
On Fri, 24 Dec 2004 04:51:21 GMT, cah2240 <ca*****@mail.usf.edu>
wrote:
That site has a good intro on what it can do to receive one piece of
information back. However is it possible to pass more? This object is
supposed to be able to pass a full DOM tree, but I haven't found any specs
on what the tree should be sent as from the server or how to parse it
after I receive it.


use POST or PUT and send a text serialisation of the DOM:

xmlhttp.send(xmlObj.xml)

and it's sent unencoded, you can load it into an XML document on the
server with something like:

xml=Server.CreateObject("Msxml2.DOMDocument")
xml.load(Request)

In php it will be in $HTTP_RAW_POST_DATA, and you can parse it into an
XML object.

Jim.
Jul 23 '05 #2


cah2240 wrote:
I have been searching all over the place for a good full explanation of
what can be passed back and forth using the XMLHttpRequest Object.

http://jibbering.com/2002/4/httprequest.html

That site has a good intro on what it can do to receive one piece of
information back. However is it possible to pass more? This object is
supposed to be able to pass a full DOM tree, but I haven't found any specs
on what the tree should be sent as from the server or how to parse it
after I receive it.


If the server sends XML (which is usually judged by the Content-Type
header it sends, e.g. application/xml or text/xml and for Mozilla
probably application/xhtml+xml) then the XMLHttpRequest object parses
the HTTP response body automatically and makes the DOM document available as
httpRequest.responseXML

You might want to check
<http://www.faqts.com/knowledge_base/view.phtml/aid/17226/fid/616>
for more details.

As for the server side scripting you need to send a HTTP response with
the serialized XML in the response body and the response headers
declaring the Content-Type e.g. application/xml.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3
Martin Honnen:

If the server sends XML (which is usually judged by the Content-Type
header it sends, e.g. application/xml or text/xml and for Mozilla
probably application/xhtml+xml) then the XMLHttpRequest object parses
the HTTP response body automatically and makes the DOM document
available as
httpRequest.responseXML

You might want to check
<http://www.faqts.com/knowledge_base/view.phtml/aid/17226/fid/616>
for more details.

As for the server side scripting you need to send a HTTP response with
the serialized XML in the response body and the response headers
declaring the Content-Type e.g. application/xml.


I'm also trying to parse some xml which is generated by php and then
send back again. But now i am a bit confused.
In php i set the header to application/xml and then just echo it. But
responseXML just has one child with the value null, thereas responseText
contains the complete xml i generated.
From the AppleDev Website i have an example which parses an xml
document and they access it with normal dom methods. The difference is
that they request an already existing xml file from the server.

Lets see if i understand it right:
- if i request a regular file containing xml from the server, then it is
accessible with dom methods in responseXML.
- if the xml is created with server side scripting i need to do
something like this:

function createXMLFromString () {
var xmlParser, xmlDocument;
try {
xmlParser = new DOMParser();
xmlDocument = xmlParser.parseFromString(xmlhttp.responseText,
'text/xml');
return xmlDocument;
}
catch (e) {
output("Can't create XML document.");
return null;
}
}

and then i can access xmlDocument with regular dom methods?
Would be great if you could clear things up for me
Jul 23 '05 #4


Börni wrote:

- if the xml is created with server side scripting i need to do
something like this:

function createXMLFromString () {
var xmlParser, xmlDocument;
try {
xmlParser = new DOMParser();
xmlDocument = xmlParser.parseFromString(xmlhttp.responseText,
'text/xml');


No, I see no need to parse responseText, if the XML sent to the browser
has the proper Content-Type header and the encoding is properly declared
then responseXML should work. The browser doesn't really know or care
whether that XML sent to it stems from a static XML document the HTTP
server sends or from a PHP page run on the server.
Thus if you have any problems that the response from your PHP script is
not properly parsed by the browser then I would guess that there is
something wrong with your PHP trying to send XML.
PHP is byte oriented and mainly geared to create output in 8bit
encodings like ISO-8859-1 while XML parsers are not required to
understand such encodings with XML favouring Unicode and encodings such
as UTF-8 or UTF-16.
Thus if you want to output XML with a PHP page in an 8bit encoding you
might want to do it as follows:

<?php
$xmlString = '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n";
$xmlString .=
'<root><text xml:lang="de">Umlaute: ä, ö, ü</text></root>';
header('Content-Type: application/xml');
echo utf8_encode($xmlString);
?>

That way I have no problems here with the generated XML, whether I use
browsers like Mozilla, IE 6, Opera 8.00 beta to directly render the XML
sent from the PHP or whether I try to consume the XML with the
XMLHttpRequest object and access responseXML.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #5
Martin Honnen:
PHP is byte oriented and mainly geared to create output in 8bit
encodings like ISO-8859-1 while XML parsers are not required to
understand such encodings with XML favouring Unicode and encodings such
as UTF-8 or UTF-16.
Thus if you want to output XML with a PHP page in an 8bit encoding you
might want to do it as follows:

<?php
$xmlString = '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n";
$xmlString .=
'<root><text xml:lang="de">Umlaute: ä, ö, ü</text></root>';
header('Content-Type: application/xml');
echo utf8_encode($xmlString);
?>


Well, actually i am working in php5, there i have the new DomDocument
object. And so then i say "echo DomDocument->savexml()" it should also
be an utf-8 string. I even tried to explicitely set the encoding:
DomDocuemnt->encoding="UTF-8";
Jul 23 '05 #6
Well, actually i am working in php5, there i have the new DomDocument
object. And so then i say "echo DomDocument->savexml()" it should also
be an utf-8 string. I even tried to explicitely set the encoding:
DomDocuemnt->encoding="UTF-8";


Never Mind. The encoding is right and all.
The problem seems to be that the xml gets passed through another php
file before it finally reaches the browser.
But thats too offtopic.
Jul 23 '05 #7


Börni wrote:

Well, actually i am working in php5, there i have the new DomDocument
object. And so then i say "echo DomDocument->savexml()" it should also
be an utf-8 string. I even tried to explicitely set the encoding:
DomDocuemnt->encoding="UTF-8";


We are getting off topic here in comp.lang.javascript, but if I use the
following example with PHP 5

<?php
$xmlDocument = new DOMDocument();

$root = $xmlDocument->createElement('root');
$text = $xmlDocument->createElement('text');
$text->appendChild($xmlDocument->createTextNode(utf8_encode('Umlaute: ä,
ö, ü')));
$root->appendChild($text);
$xmlDocument->appendChild($root);
header('Content-Type: application/xml');
echo $xmlDocument->saveXML();
?>

then browsers and their XMLHttpRequest objects deal with the outputted
XML just fine.

If you still run into problems then try a PHP group.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #8
Martin Honnen wrote:

We are getting off topic here in comp.lang.javascript, but if I use the
following example with PHP 5

<?php
$xmlDocument = new DOMDocument();

$root = $xmlDocument->createElement('root');
$text = $xmlDocument->createElement('text');
$text->appendChild($xmlDocument->createTextNode(utf8_encode('Umlaute: ä,
ö, ü')));
$root->appendChild($text);
$xmlDocument->appendChild($root);
header('Content-Type: application/xml');
echo $xmlDocument->saveXML();
?>

then browsers and their XMLHttpRequest objects deal with the outputted
XML just fine.

If you still run into problems then try a PHP group.


Well, actually the reason why i wasted the last to hours is kind a
funny: one of the included php files contained a linebreak after the ?>.

And that just somehow broke everything.
Its still offtopic, but its too amusing.
Jul 23 '05 #9

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

Similar topics

1
by: Elizabeth Harmon | last post by:
Good Evening, I am new to the XMLHTTPRequest Object and it's use but i am doing pretty good with it since it's realtively simple? I am having one problem in using a Get method. I am...
20
by: chris.schwalm | last post by:
This is part II of this <a...
1
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...
7
by: pamelafluente | last post by:
The precious input given by Laurent, Martin, Benjamin about XMLHttpRequest in Javascript, has made me think that perhaps I could improve what I am currently doing by using Ajax. Let's make it...
1
by: weston | last post by:
So, the following apparently works as a method of grafting a method onto an object (using the squarefree JS shell): obj = { x: 1, inc: null } result obj.inc = function () { this.x++ } result...
1
by: vocalise | last post by:
The title probably isn't very clear, but I haven't been able to find this problem (or I must be having problems figuring out which search strings to use) so I apologize if this has been addressed...
5
by: Peter Michaux | last post by:
Hi, The FAQ correctly says the following: "Mozilla (NN6.2+, Firefox, Ice Weasle etc), Opera 7.6+, Safari1.2+, the Windows version of IE versions 5+, and some other browsers provide the XML...
1
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...
5
by: HugeBob | last post by:
Hi All, I've got a question about Asynchronous vs Synchronous mode with the XMLHttpRequest object. What are the ramifications of using one mode vs the other? If the script uses Asynchronous...
25
by: q-rious | last post by:
Hello All, I have a question regarding XMLHttpRequest. I have the following code (as part of a much larger file): function loadXMLDoc(url) { // branch for native XMLHttpRequest object if...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.