Stretchwickster
Programmer
Dear All,
I was just browsing through a magazine and noticed an article on AJAX that had a small (and very briefly explained) example. It didn't work first time so I tinkered around with the appropriate code (in the processResponse function) until it worked in Firefox. I browsed the same page in IE and I got a blank page instead of some data in my "result" div tag.
I debugged the code and found that IE was stopping on the line highlight in blue below. I looked up getElementsByTagName and I seem to be using it correctly. But is this one of those cases where IE is not following standards or have I made some error?
AjaxExample.xml
AjaxExample.htm
Clive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
I was just browsing through a magazine and noticed an article on AJAX that had a small (and very briefly explained) example. It didn't work first time so I tinkered around with the appropriate code (in the processResponse function) until it worked in Firefox. I browsed the same page in IE and I got a blank page instead of some data in my "result" div tag.
I debugged the code and found that IE was stopping on the line highlight in blue below. I looked up getElementsByTagName and I seem to be using it correctly. But is this one of those cases where IE is not following standards or have I made some error?
AjaxExample.xml
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<days>
<day name="Sunday">Mow the lawn.</day>
<day name="Monday">Pay the rent.</day>
<day name="Tuesday">Wash the dog.</day>
<day name="Wednesday">Do the laundry.</day>
<day name="Thursday">Important Meeting.</day>
<day name="Friday">Meal out.</day>
<day name="Saturday">Go to the match.</day>
</days>
AjaxExample.htm
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en" lang="en">
<head>
<title></title>
<script language="Javascript" type="text/javascript">
<!-- Hide script from old browsers
function createRequestObject()
{
var requestObj;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
{
requestObj = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
requestObj = new XMLHttpRequest();
}
return requestObj;
}
var http = createRequestObject();
function makeRequest()
{
http.open('get', 'AjaxExample.xml');
http.onreadystatechange = processResponse;
http.send(null);
}
function processResponse()
{
if (http.readyState == 4)
{
var xmldoc = http.responseXML;
var dayIndex = document.activities.select_day.selectedIndex;
[COLOR=blue]var myActivity = xmldoc.getElementsByTagName("day")[dayIndex].firstChild.data;[/color]
alert(myActivity);
document.getElementById('result').innerHTML = myActivity;
}
}
// End hiding script -->
</script>
</head>
<body>
<div id="query">
<p>Select a day from the drop-down menu:</p>
<form name="activities">
<select id="select_day" onchange="makeRequest()">
<option value="Sunday">Sunday</option>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
</select>
</form>
</div>
<div id="result"></div>
</body>
</html>
Clive

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096