Too Cool for Internet Explorer


Swobodin's Profile | Swobodin's Blog | Back to Fedora Tunisia

Flirting with AJAX

AjaxI started to find out about AJAX, a fashion Web technology, which stands for Asynchronous JavaScript And XML; Hatem’s blog helped me a lot, and the Internet is a huge source of information.
A “hello world” application is like the following: it requests data from page.php and writes the content between div tag identified by “willchange”. Not as complicated as it seems to be…
<!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 name="generator" content=
"HTML Tidy for Linux/x86 (vers 12 April 2005), see www.w3.org" />
<script type="text/javascript">
    var http = new XMLHttpRequest();
    function sndReq() {
        http.open("get","page.php");
        http.setRequestHeader("user-agent","A robot made by Swobodin, just to test :-P ");
        http.onreadystatechange = handleResponse;
        http.send(null);
        
    }
 
        function handleResponse() {
     if (http.readyState == 4) {
     var response = http.responseText;
     document.getElementById("willchange").innerHTML = response;
              }
        }
</script>
<title></title>
</head>
<body onload="sndReq()">
    <div id="willchange">
    </div>
</body>
</html>
Another script to show memory status (works only on UNIX)
<!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>
<script type="text/javascript">
    var http = new XMLHttpRequest();
    window.setInterval("RqSend()",1000);
    function RqSend() {
    http.open("get", "/proc/meminfo",true);
    http.onreadystatechange = update_all;
    http.send(null);
    }
    function update_all() {
        if (http.readyState == 4) {
            var response = http.responseText;
            document.getElementById("main").innerHTML = "<pre>\n"+response+"\n<\/pre>";
        }
    }
   
</script>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 12 April 2005), see www.w3.org" />
<title>Memory Status</title>
</head>
<body onload='RqSend()'>
    <div id="main">
    </div>
</body>
</html>

 
It’s crazy what you can do with AJAX! Flickr and Gmail are typical examples of the perfect mastering of it.
I liked the gallery application, lightbox, you may check it out here

Related posts

(sometimes, the plugin foolishes)
Chess is confusing me
Murphy programming laws
Snipper
Switching keyboard
Team Soccer names

Technorati tags

One Response to “Flirting with AJAX”

  1. swifty Says:

    cooooooooooooooooooooooooooooooooooooooooooooooooooooooooooolll

    I like this tech a lot toooooo

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

 
 

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a


Top Tunisie Blogs