Ajax Template - Ajax Patterns

Ajax Template

From Ajax Patterns

Revision as of 10:36, 3 June 2007; view current revision
←Older revision | Newer revision→

Sometimes it's hard to remember the exact syntax for creating the three cornerstones of an Ajax App - the HTML, the CSS, and of course the Javascript. Here's a little template you can cut-and-paste to get you started.

And here's a Unit Test Template, so no excuses for not performing Browser-Side Tests.

Contents

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
     <meta name="keywords" content="Footy,Bluebaggers" />
     <meta name="description" content="News and History of the Bluebaggers" />
     <title>Hello World!</title>
     <script type="text/javascript" src="app.js"></script>
     <link rel="stylesheet" type="text/css" href="app.css"/>
  </head>
  <body>
      <h1>Hello World!</h1>
      <input id="search" name="search" />
  </body>
</html>

CSS

body { background-color: white; }
div.error { font-color: red; }
#search { width: 200px; }

Javascript

function $(id) { return document.getElementById(id); }

window.onload = function() {
  $("search").onclick = function() { alert("The search begins!"); }
}