I haven’t been touching code for quite some time. It was amazing that I even worked with my laptop for two months without knowing that I am not an administrator for the Windows system. At that time, I know, I cannot call myself a technical person any more.
However, I am still passionate about technology. Recently, I noticed that there are great changes around the web. A new revolution is coming, led by the application of Flickr, Google Map, and Gmail. It is very inspiring. AdoptivePath gives it a name called AJAX.
I setup a sample application below.
// remote scripting library
// (c) copyright 2005 modernmethod, inc
var sajax_debug_mode = false;
var sajax_request_type = "GET";
function sajax_debug(text) {
if (sajax_debug_mode)
alert("RSD: " + text)
}
function sajax_init_object() {
sajax_debug("sajax_init_object() called..")
var A;
try {
A=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
A=new ActiveXObject("Microsoft.XMLHTTP");
} catch (oc) {
A=null;
}
}
if(!A && typeof XMLHttpRequest != "undefined")
A = new XMLHttpRequest();
if (!A)
sajax_debug("Could not create connection object.");
return A;
}
function sajax_do_call(func_name, args) {
var i, x, n;
var uri;
var post_data;
uri = "/scripts/php/example_wall.php";
if (sajax_request_type == "GET") {
if (uri.indexOf("?") == -1)
uri = uri + "?rs=" + escape(func_name);
else
uri = uri + "&rs=" + escape(func_name);
for (i = 0; i < args.length-1; i++)
uri = uri + "&rsargs[]=" + escape(args[i]);
uri = uri + "&rsrnd=" + new Date().getTime();
post_data = null;
} else {
post_data = "rs=" + escape(func_name);
for (i = 0; i < args.length-1; i++)
post_data = post_data + "&rsargs[]=" + escape(args[i]);
}
x = sajax_init_object();
x.open(sajax_request_type, uri, true);
if (sajax_request_type == "POST") {
x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}
x.onreadystatechange = function() {
if (x.readyState != 4)
return;
sajax_debug("received " + x.responseText);
var status;
var data;
status = x.responseText.charAt(0);
data = x.responseText.substring(2);
if (status == "-")
alert("Error: " + data);
else
args[args.length-1](data);
}
x.send(post_data);
sajax_debug(func_name + " uri = " + uri + "/post = " + post_data);
sajax_debug(func_name + " waiting..");
delete x;
}
// wrapper for add_line
function x_add_line() {
sajax_do_call("add_line",
x_add_line.arguments);
}
// wrapper for refresh
function x_refresh() {
sajax_do_call("refresh",
x_refresh.arguments);
}
var check_n = 0;
function refresh_cb(new_data) {
document.getElementById("wall").innerHTML = new_data;
document.getElementById("status").innerHTML = "Checked #" + check_n++;
setTimeout("refresh()", 5000);
}
function refresh() {
document.getElementById("status").innerHTML = "Checking..";
x_refresh(refresh_cb);
}
function add_cb() {
// we don't care..
}
function add() {
var line;
var handle;
handle = document.getElementById("handle").value;
line = document.getElementById("line").value;
if (line == "")
return;
x_add_line("[" + handle + "] " + line, add_cb);
document.getElementById("line").value = "";
}
refresh();
Note: Here is the full script of the conversation
I don't know if you noticed or not, this is just a simple static HTML page, but you can write on it, and change the content of this page. This application cannot be simpler, but it is a great change in mindset many web developers. It is simply a Javascript version of SOAP (without complicated codes), but it works great.
Sorry for technical terms in this entry. I know someone will jump out and post "No, No" as my previous technical post. Excuse me for one day. AJAX is just so inspiring for me.
I know the world of web will not be the same as before. Just as HTML is so simple, but it changes the world. Keep it simple and stupid is always a good way to use technology. It is simpler than SOAP, and cooler than other XML application.