473,388 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Total N00b question

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...tting_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

Jan 27 '06 #1
3 1658
Matt Fuerst wrote:
We are working a very simple AJAX example that we downloaded from the
Mozilla Dev Center
No AJAX application is simple :-)

[...] 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.
Yep. As per usual.

[...] 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...


Could be. FAQ. http://xml.silmaril.ie/developers/serversoftware/

///Peter
Jan 28 '06 #2

You're not alone Matt. I've been programming for 10+ years in several
different languages and just attempted to do exactly what you were
trying to do and came across a little frustration of my own. This
should work for IE. Load these files in the same directory and you
should get alerted when you go to test.asp. Hope this helps.

D.
file: test2.asp
-------------------------------------------
<%
response.buffer=true
response.contentType = "text/xml"
%>
<root>
<value>
<nm>I'm a test.</nm>
<party>Darrell</party>
</value>
<value>
<nm>test 2</nm>
<party>Robinson </party>
</value>
</root>
--------------------------------------------

file: test.asp
--------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY onload="makeRequest('test2.asp');">
<script type="text/javascript" language="javascript">

var http_request = false;

function makeRequest(url) {

http_request = false;

if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
// See note below about this line
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new
ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);
http_request.send(null);

}

function alertContents() {

if (http_request.readyState == 4) {
if (http_request.status == 200) {
var xmldoc = http_request.responseXML;
//var root_node = xmldoc.getElementsByTagName('root').item(0);
//alert(root_node.firstChild.data);
err = xmldoc.parseError;
if (err.errorCode != 0) {
alert("Error: " + err.reason);
} else{
var xml = xmldoc.getElementsByTagName('root').item(0);
var y =
xmldoc.getElementsByTagName('root').item(0).getEle mentsByTagName('value').length-1;
for(var x=0;x<=y;x++){
alert(xml.getElementsByTagName('value').item(x).ge tElementsByTagName('nm').item(0).firstChild.data)
alert(xml.getElementsByTagName('value').item(x).ge tElementsByTagName('party').item(0).firstChild.dat a)
} }
} else {
alert('There was a problem with the request.');
}
}

}
</script>
<span
style="cursor: pointer; text-decoration: underline"
onclick="makeRequest('test2.asp')">
Make a request
</span>

</BODY>
</HTML>
---------------------------------------------------
--
dtrobinson
------------------------------------------------------------------------
dtrobinson's Profile: http://techiegroups.com/member.php?userid=64
View this thread: http://www.techiegroups.com/showthread.php?t=100596

Feb 7 '06 #3
vioLab
1
Hey,
I just wanted to post a quick comment here in case anyone else googles this thread as I came across it yesterday when experiencing the same problem but neither of the above solutions helped. In the end the problem was that there was a line break between the end of my asp, ie. %> and the xml declaration - a very simple thing but it was frustrating my ajax efforts for hours. Might help someone else...
Apr 28 '06 #4

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

Similar topics

1
by: Matt | last post by:
I'd like to overwrite just one line of a binary file, based on a position set by seek(). Is there no way to do this? As far as I can tell I need to read the whole file, change the line, and write...
3
by: Anupam Kapoor | last post by:
hi all, a python n00b, so please bear with me. i have a simple question: i generally name python sources as a-simple-python-example.py. when i try to import a module named as above, i...
1
by: newgenre | last post by:
I am using a pre-built package of code for my site, which is called EasyDisc. All it does is it creates an interactive forum on your site, like any forum you see anywhere. I am having a problem...
4
by: onefry | last post by:
Hey I have this prog that i'm working on, starting my first c++ class and kind of a n00b to programming here it is #include <iostream> #include <cstdlib> using namespace std;
6
by: Charles | last post by:
I am learning from the Accelerated C++ book. The following example doesn't work and I don't know why: #include <iostream> #include <string> int main () { const std::string exclam = "!"; const...
3
by: rtlshred | last post by:
Hello I have just, just started C++ programing. the complier I am using is Dev C++ Here is my question: Once I have written some code, How do I run the program and see the output?
5
by: alanb | last post by:
Hi, hope someone can help, I need to be able to keep a running total of radio buttons selected, as a user goes through a set of 16 questions, devided in to 4 catorgories, then on "submit" have the...
21
beacon
by: beacon | last post by:
Hello to everybody, I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know),...
2
by: benwah1983 | last post by:
Greetings, Here is my problem: The following code shows a div with two small nested divs (images with a title), then the div is closed. Another one opens and a "random text" is displayed. <div...
4
by: ig | last post by:
First off, I'm a python n00b, so feel free to comment on anything if I'm doing it "the wrong way." I'm building a discrete event simulation tool. I wanted to use coroutines. However, I want to know...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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
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...

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.