11182006 1338 GMT-6

Im doing a tutorial on AJAX and PHP. 
http://www.phpbuilder.com/columns/white-eisenhamer20060916.php3

This is the php page:
<?php
// Figure out our time format. If none is
// provided, default to RFC 2822 format:
$format = isset($_GET['format']) ?
  $_GET['format'] : 'r';

// Generate the date:
date_default_timezone_set('America/New_York');
$dstr = date($format);

// Define that we are returning XML
// content & not to cache:
header('Content-Type: text/xml');
header('Cache-control: no-cache');

// Now output a valid XML file:
echo <<<EOXML
<?xml version="1.0" ?>
<result>{$dstr}</result>
EOXML;
?>

And this is the ? page:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd";>
<html>
<head>
</head>
<body>

<pre>
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
&lt;html xmlns="http://www.w3.org/1999/xhtml";>
&lt;head>
&lt;title>Formatted Time&lt;/title>
&lt;meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
&lt;script type="text/javascript">
// Declare our request variable.
var request = false;

// Define a function that will make our request for us:
function retrieveDate() {
  // Clear the curent request
  request = false;

  // Generate the request object and handle different browsers:
  if (window.XMLHttpRequest) { 
        
    request = new XMLHttpRequest();
  } else if (window.ActiveXObject) { // Internet Explorer
    request = new ActiveXObject("Microsoft.XMLHTTP");
  }

  // If we don't have a request object, then error out.
  if (!request) {
    alert('Browser does not support AJAX!');
    return false;
  }

  // Ok, now we are ready. Make the request, and tell it to run the
  // function 'updateDate' when it gets data back.
  request.onreadystatechange = updateDate;

  // Open the connection, sending the current value of the form element:
  request.open('GET',
    'time.php?format=' + escape(document.myform.dformat.value), true);
  request.send(null);
}

// The function that will accept the data, and update the page:
function updateDate() {
  // Make sure that the state is '4', which means finished:
  if (request.readyState == 4) {
    // Make sure that the status is 200, or 'ok'
      if (request.status == 200) {
        // If so, read the result back in as XML:
        var xml = request.responseXML;

      // Now, parse the 'result' out of the XML:
      var result = xml.getElementsByTagName('result').item(0);

      // And now, update the text on the page:
      var text = document.getElementById('datetext');
      text.innerHTML = result.firstChild.data;


    } else {
      alert('Error performing request!' + request.status);
    }
  }
}
&lt;/script>
&lt;/head>
&lt;body>
&lt;p>Click the update button below to receive the current date. Insert
any valid PHP date() format string in the field to format it
accordingly.&lt;/p>
&lt;p id="datetext">--DATE GOES HERE--&lt;/p>
&lt;form id="myform" name="myform">&lt;p>
&lt;input type="text" id="dformat" name="dformat" value="r" />
&lt;input type="button" value="Update" onclick="retrieveDate()" />
&lt;/p>&lt;/form>
&lt;/body>
&lt;/html>
</pre>
</body>
</html>


I named the Ajax page just time.html and the time.php page.
But when I open the time.html page I get a page that is all text.
I know this is WAY off topic for php but I was hoping someone would put
me on track.

wade

Reply via email to