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.
I found the flickering I mentioned only happens when using Firefox. When using Internet Explorer it doesn’t happen. Since Firefox is constantly increasing it’s share of users I don’t think the technique is completely ready for commercial usage yet, unless there is some way to improve the behaviour in Firefox. (According to this recent survey http://www.netapplications.com/news.asp Firefox now has more than 8% market share.)
Hi jianshuo, I visited your kijiji forum and found that the order of threads is from latest to oldest. I don’t think this is a proper way to display the threads, since the user has to scroll down the pape or go the first pape of the topic in order to find what the topic maker’s original sayings are. I might be wrong. Just wanna leave a bit comment to you anyway. ^^;
Hello,
Great blog!
I recently started up my own site, and I’d like to incorporate a “graffiti” like feature onto my own site. I was wondering if 1. this is possible with Sajax and 2. if you could give me some advice.
Thank you very much – I greatly enjoy this site,
Nate.
very interesting:)
I’ll study it for a while, hehe.
Nate, just check the SAJAX site (I provided the link) and it is the simplist example of SAJAX. You can set it up by yourself. The only thing you need to take care but the mannual didn’t mention is, you need to set 777 permission for file wall.html
Jian, thanks for you response.
I’ll give it a shot and let you know if I can get it working. Keep up the good work on your site!
Nate.
Suprised and happy to see the AJAX in your blog, since I’ve been following up with AJAX recently. There is another very good AJAX framework: DWR(http://www.getahead.ltd.uk/dwr/intro.html), maybe you would like to take a look.
By the way, the above sample Sajax would not work on Firefox.
I put “TIMÃO” and “RAÇA” in message and appears “RA?” and “TIM?br>”… How can i do this be ok…????
Maybe you want to take a look of the following AJAX + XUL framework. We believe it makes developing the RIA web applications as simple as developing a desktop application.
http://zk1.sf.net
Live demo
http://www.potix.com/zkdemo/userguide
Henri
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.
hi