M
Matt Fuerst
Hi all,
I pre-apologize for the level of stupidity that this message will
contain. I nearly guarantee that your IQ will be lowered by the end of
this message.
Me and a co-worker (I only bring him into this to try to divide the
stupidity in half, thus making us each appear only half as dumb as we
could, oh wait, will we come off twice as dumb since there are two of
us, maybe this plan is backfiring on me)...
We are working a very simple AJAX example that we downloaded from the
Mozilla Dev Center
(http://developer.mozilla.org/en/docs/AJAX:Getting_Started). Using the
presented example everything comes out dandy. However the example loads
a static XML file called test.xml.
Obviously a static XML file isn't too dynamic, so we wanted, nice and
easy to start to make the example more dynamic and dynamically generate
the XML data...
We converted the test.xml file to an ASP file...
Flat test.xml file:
<?xml version="1.0" ?>
<root>
I'm a test.
</root>
We created a test.asp file with the following:
<%
response.write( "<?xml version=""1.0"" ?>" )
response.write( "<root>" )
response.write( "Im a test" )
response.write( "</root>" )
%>
Which we imagined would have the same result. We can load test.xml or
test.asp in our browser directly and both look the same in our browser.
However when we load our Ajax HTML page and click the button to load
our XML file, it refuses to parse the XML with the ASP generated XML.
As a sidenote, this all works fine in Firefox.
Many hours later we figured it must have had something to do with the
headers that IIS and ASP were passing to the browser. So we loaded
Apache + PHP 5. We created a test.php file which outputs our simple XML
document. Again loading up test.php directly is fine, but within the
Ajax app it refuses to parse (in Internet Explorer, again Firefox
handles it fine). We also added header() php function calls before we
pass the XML data to force it to be text/xml data type, still no go. I
changed Apache to pass .xml files into PHP and pass along to the
client, in case the Ajax was not accepting of a .php file passing an
XML file... still no go..
Ok.. so there's a day in the bank.. the longest time ever to create a
"Hello World" application (I hope my boss isn't reading this since I am
going to be pink slipped for being so unproductive).
We decided it must be some problem with the Types, Mime Types, all that
stuff that IE still was refusing to see our "dynamically generated" XML
file...
We rewrote our dynamic XML output using the XML DOM model... I create
a very simple document named test2.php as follows:
<?php
$doc = new DOMDocument();
$doc->formatOutput = true;
$now = time();
$developers = $doc->createElement( "time" );
$doc->appendChild( $developers );
$developers->appendChild( $doc->createTextNode($now) );
echo $doc->saveXML();
?>
My JavaScript to parse out the data looks like:
function alertContents()
{
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
alert(http_request.responseText);
var xmldoc = http_request.responseXML;
var root_node = xmldoc.getElementsByTagName('time').item(0);
if( root_node )
alert(root_node.firstChild.data);
else
{
alert( 'Poop the bed' );
}
}
else
{
alert('There was a problem with the request.');
}
}
}
We always see "Poop the Bed" in IE and it works fine in Firefox.
That's officially the end of the rope... We're going to go home now and
drown ourselves in our mediocrity and hope to return to work Monday and
read the mockings of our fellow developers here in this public forum,
and maybe an idea or two on what the heck we are doing wrong...
Thanks!
Matt
I pre-apologize for the level of stupidity that this message will
contain. I nearly guarantee that your IQ will be lowered by the end of
this message.
Me and a co-worker (I only bring him into this to try to divide the
stupidity in half, thus making us each appear only half as dumb as we
could, oh wait, will we come off twice as dumb since there are two of
us, maybe this plan is backfiring on me)...
We are working a very simple AJAX example that we downloaded from the
Mozilla Dev Center
(http://developer.mozilla.org/en/docs/AJAX:Getting_Started). Using the
presented example everything comes out dandy. However the example loads
a static XML file called test.xml.
Obviously a static XML file isn't too dynamic, so we wanted, nice and
easy to start to make the example more dynamic and dynamically generate
the XML data...
We converted the test.xml file to an ASP file...
Flat test.xml file:
<?xml version="1.0" ?>
<root>
I'm a test.
</root>
We created a test.asp file with the following:
<%
response.write( "<?xml version=""1.0"" ?>" )
response.write( "<root>" )
response.write( "Im a test" )
response.write( "</root>" )
%>
Which we imagined would have the same result. We can load test.xml or
test.asp in our browser directly and both look the same in our browser.
However when we load our Ajax HTML page and click the button to load
our XML file, it refuses to parse the XML with the ASP generated XML.
As a sidenote, this all works fine in Firefox.
Many hours later we figured it must have had something to do with the
headers that IIS and ASP were passing to the browser. So we loaded
Apache + PHP 5. We created a test.php file which outputs our simple XML
document. Again loading up test.php directly is fine, but within the
Ajax app it refuses to parse (in Internet Explorer, again Firefox
handles it fine). We also added header() php function calls before we
pass the XML data to force it to be text/xml data type, still no go. I
changed Apache to pass .xml files into PHP and pass along to the
client, in case the Ajax was not accepting of a .php file passing an
XML file... still no go..
Ok.. so there's a day in the bank.. the longest time ever to create a
"Hello World" application (I hope my boss isn't reading this since I am
going to be pink slipped for being so unproductive).
We decided it must be some problem with the Types, Mime Types, all that
stuff that IE still was refusing to see our "dynamically generated" XML
file...
We rewrote our dynamic XML output using the XML DOM model... I create
a very simple document named test2.php as follows:
<?php
$doc = new DOMDocument();
$doc->formatOutput = true;
$now = time();
$developers = $doc->createElement( "time" );
$doc->appendChild( $developers );
$developers->appendChild( $doc->createTextNode($now) );
echo $doc->saveXML();
?>
My JavaScript to parse out the data looks like:
function alertContents()
{
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
alert(http_request.responseText);
var xmldoc = http_request.responseXML;
var root_node = xmldoc.getElementsByTagName('time').item(0);
if( root_node )
alert(root_node.firstChild.data);
else
{
alert( 'Poop the bed' );
}
}
else
{
alert('There was a problem with the request.');
}
}
}
We always see "Poop the Bed" in IE and it works fine in Firefox.
That's officially the end of the rope... We're going to go home now and
drown ourselves in our mediocrity and hope to return to work Monday and
read the mockings of our fellow developers here in this public forum,
and maybe an idea or two on what the heck we are doing wrong...
Thanks!
Matt