[Ilugc] [TIP] HTML client side processing to talk to CGI

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Mon, 21 Nov 2011 07:42:06 +0530

Typically the CGI is not directly exported to the user like yesterday's example.

It forms part of a HTML Page that allows us to do Ajax and other javascript
 processing.

HTML has got a DOM structure(Document Object Model) tree hierarchy.

For example,

this page,

<html>
       <head>
                <title> Test </title>
       </head>

        <body>
                     <div id="left"> </div>
                     <div id="right"> </div>
        </body>
</html>

has a DOM structure like this:

                        html

                 head        body
                title        div(left)   div(right)

So as you can see, it is very easy to understand how this
structure works.

Now both CSS and javascript uses this model to act on
various HTML tags.

For instance we identify the <div> tag with id attribute "left" like this.

$('div[#left]').

This is also jQuery. We will talk about jQuery tomorrow.

Only when we use all this do we get a smooth user experience of giving
  CGI functionality in a very interactive way.

So to talk to the CGI script we saw yesterday we use javascript and Ajax
 like this:

<script src="jquery-1.6.2.js" type="text/javascript"></script>
<script type="text/javascript">
   $(function() {
             $('#right').load('/cgi-bin/first.cgi', function() {
                  $('input[type=button]').click(function() {
                      param = $('input[type=text]').val();
                      $('#right').load('/cgi-bin/first.cgi?param=' + param);
               });
        });
 });
</script>

This portion is coded in the <head> container of the above HTML structure.

As you can see we are deeply into javascript and jQuery.

We will see that tomorrow.

-Girish
-- 
G3 Tech
Networking appliance company
web: http://g3tech.in ?mail: girish at g3tech.in

Other related posts: