Download link here
Transcript
Mozilla Ajax documentation:
http://developer.mozilla.org/en/docs/AJAX
XMLHttpRequest documentation
http://documentation:
developer.apple.com/internet/webcontent/xmlhttpreq.html
Ajax applications
TiddlyWiki: http://www.tiddlywiki.com
Gregarius RSS Reader: http://gregarius.net
Basecamp: http://www.basecamphq.com
Geocode lookup (with source):
http://highearthorbit.com/projects/geocode/
Ajax toolsets
Prototype, a Javascript framework for web apps:
http://prototype.conio.net/
Sajax, Ajax for PHP: http://www.modernmethod.com/sajax/
Ajax Framework
The following files are the summation of the
framework code developed in the article above. It can
serve as a skeleton for building your own Ajax
applications.
Place
these
files
in
your
/Library/WebServer/Documents directory on your Mac,
and turn on “Personal Web Sharing” in the “Sharing
Preference Pane”.
AjaxFramework.js
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == “Microsoft Internet Explorer”){
ro = new ActiveXObject(“Microsoft.XMLHTTP”);
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function handleResponse() {
if(http.readyState == 1){
// request loading
document.getElementById(“status”).innerHTML
= “requesting...”;
}
else if(http.readyState == 4) {
}
= “error: “ + http.statusText;
}
}
function sendRequest() {
var query =
document.getElementById(“queryInput”).value;
var queryURL = “service.php?q=” + query;
http.open(‘get’, queryURL);
http.onreadystatechange = handleResponse;
http.send(null);
return true;
}
AjaxDemo.html
<html>
<head>
<script type=”text/javascript”
src=”AjaxFramework.js”></script>
</head>
<body>
<noscript>
Your browser does not support Javascript. Please
upgrade your browser or enable Javascript to use
this site.
</noscript>
<input type=”text” size=”30” id=”queryInput”
value=”” />
<a href=’#’ onClick=”sendRequest();”>Send</a>
<div id=”status”> </div><br/>
<textarea rows=”20” cols=”70” id=”responseArea”
value=”” ></textarea>
</body>
</html>
service.php
<?php
echo $_GET[“q”];
?>
MT
About The Author
Andrew Turner is a Systems Development Engineer with Realtime Technologies,
Inc. (www.simcreator.com) and has built robotic airships, automated his house,
designed spacecraft, and in general looks for any excuse to hack together cool
technology. You can read more about his projects at www.highearthorbit.com.
// request complete
if(http.status == 200) {
®
// OK returned
var response = http.responseText;
document.getElementById(“status”).innerHTML
= “loaded”;
document.getElementById(“responseArea”).innerHTML
= response;
}
else
{
document.getElementById(“status”).innerHTML
110
SAMPLER • 2006
Get MacTech delivered to
your door at a price FAR
BELOW the newstand price.
And, it’s RISK FREE!
store.mactech.com/riskfree
WWW.MACTTECH.COM