Msxml2.XMLHTTP formats my XML, why?

G

gfaraj

Hello, I'm working on an ajax application in which I request things
from my php documents. The php responds in XML format. Now, the problem
is that when I receive that data using the ActiveX object
Msxml2.XMLHTTP, it formats my responseText, even though the
Content-type is text/plain.

The php file is here: http://rafb.net/paste/results/sIDyVF79.html
The javascript used to get the response:
http://rafb.net/paste/results/rkwyRD81.html

Now, in firefox I get the response as is sent by php. In IE, I get it
formatted as if were going to be "viewed". For example:

IE's responseText:

<?xml version="1.0" ?>
- <fxlresponse>
<error id="0" />
<login session="9fhih3jljhvcnk3v5ji8jdths3" id="1" name="gfaraj"
fullname="George Faraj" type="1" />
</fxlresponse>

FF's responseText:

<?xml version="1.0"?> <fxlresponse> <error id="0" /> <login
session="dnuv2gcr0tav8mub9mc5a3tlr7" id="1" name="gfaraj"
fullname="George Faraj" type="1" /> </fxlresponse>


Why does IE do this? I tried setting the Content-type to text/xml, and
use the responseXML.xml property, but FF didn't like that.

I was thinking of just returning responseXML to the handler, but since
the handler is a Java (GWT) function, I'm not sure how I should do
that.

Does anyone have any idea of how to fix this?
Thanks.
 
G

gfaraj

The links for the files have expired.. I'll post them here instead...
I'll appreciate ANY help on this.

The php file:

<?php

header('Content-type: text/plain; charset=utf-8');
//header('Content-type: text/xml');

require_once("config.php");

$request = Data::parse(Request::httpPost());

$response = '<?xml version="1.0"?>' . "\n" .
'<fxlresponse>' . "\n";

if (User::login($request->get("name"), $request->get("password")))
{
$response .= '<error ' . "\n" .
' id="0" /> ' . "\n" .
'<login ' . "\n" .
' session="' . Session::id() . '" ' . "\n" .
' id="' . User::id() . '" ' . "\n" .
' name="' . User::name() . '" ' . "\n" .
' fullname="' . User::fullName() . '" ' . "\n" .
' type="' . User::type() . '" />' . "\n";
}
else
{
$response .= '<error ' . "\n" .
'id="2" />' . "\n";
}

$response .= '</fxlresponse>';

// Send the response
echo $response;

?>



The javascript that does the posting:


var xmlHttp = false;
if (window.XMLHttpRequest)
{
// Mozilla, Safari,...
xmlHttp = new XMLHttpRequest();
if (xmlHttp.overrideMimeType) {
xmlHttp.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject)
{
// IE
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
if (xmlHttp.overrideMimeType) {
xmlHttp.overrideMimeType('text/xml');
}
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!xmlHttp)
{
alert('Cannot create XMLHTTP instance');
return false;
}

try
{
xmlHttp.open("POST", host, true);
xmlHttp.setRequestHeader("Content-Type", "text/plain;
charset=utf-8");

xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4)
{
delete xmlHttp.onreadystatechange;

if (xmlHttp.status == 200) {
var localHandler = handler;
var responseText = xmlHttp.responseText;
handler = null;
xmlHttp = null;
(e-mail address removed)::blush:nCompletion(Ljava/lang/String;)(responseText);
} else {
handler = null;
xmlHttp = null;
alert("There was a problem retrieving the XML data:\n" +
xmlHttp.statusText);
}
}
};

xmlHttp.send(data);
return true;
}
catch (e) {
delete xmlHttp.onreadystatechange;
handler = null;
xmlHttp = null;
return false;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top