Thursday, January 27, 2011

How ajax makes things easy


A couple of days ago I was browsing the net for some remote scripting (also known as AJAX) examples and how to use the XmlHttpRequest object. However, all examples were quite nasty in imiplementation so I decided to write an nice little javascript wrapper around the XmlHttpRequest object.
// JavaScript Document
function EzRemoteScripter() {
   
//private variables
   
var _XmlHttpRequest = null;
    var
_This = null;
   
   
//public properties
   
this.GetResponseXML = function() {
        return (
_XmlHttpRequest) ? _XmlHttpRequest.responseXML : null;
    }
   
   
this.GetResponseText = function() {
        return (
_XmlHttpRequest) ? _XmlHttpRequest.responseText : null;
    }
   
   
this.GetXMLHttpRequestObj = function() {
        return
_XmlHttpRequest;
    }
   
   
//public methods
   
this.InitXmlHttpRequest = function(Method, CallUri) {
       
_InitXmlHttpRequest();
       
_This = this;
        switch(
arguments.length ) {
            case
2:
               
_XmlHttpRequest.open(Method, CallUri);   
                break;
            case
3:
               
_XmlHttpRequest.open(Method, CallUri, arguments[2]);
                break;
        }
       
        if(
arguments.length >= 4) {
           
_XmlHttpRequest.open(Method, CallUri, arguments[2], arguments[3]);
        }
    }
   
   
this.Commit = function(Data) {
        if(
_XmlHttpRequest ) {
           
_XmlHttpRequest.send(Data);
        }
    }
   
   
this.Close    = function() {
        if(
_XmlHttpRequest ) {
           
_XmlHttpRequest.abort();
        }
    }
   
   
//public events
   
this.OnUninit         = function() {};
   
this.OnLoading         = function() {};
   
this.OnLoaded         = function() {};
   
this.OnInteractive     = function() {};
   
this.OnSuccess        = function() {};
   
this.OnFailure         = function() {};
   
   
//private events
   
function _OnUninit()         { _This.OnUninit(); };
    function
_OnLoading()         { _This.OnLoading(); };
    function
_OnLoaded()         { _This.OnLoaded(); };
    function
_OnInteractive()     { _This.OnInteractive(); };
    function
_OnSuccess()         { _This.OnSuccess(); };
    function
_OnFailure()         { _This.OnFailure(); };
   
   
//private methods
   
function _InitXmlHttpRequest() {
       
_XmlHttpRequest = _GetXmlHttpRequest();
       
_XmlHttpRequest.onreadystatechange = _StateHandler;
    }
   
    function
_StateHandler() {
        switch(
_XmlHttpRequest.readyState) {
            case
0:
               
window.setTimeout("void(0)", 100);
               
_OnUninit();
                break;
            case
1:
               
window.setTimeout("void(0)", 100);
               
_OnLoading();
                break;
            case
2:
               
window.setTimeout("void(0)", 100);
               
_OnLoaded();
                break;
            case
3:
               
window.setTimeout("void(0)", 100);
               
_OnInteractive();
                break;
            case
4:
                if (
_XmlHttpRequest.status == 200) {
                   
_OnSuccess();
                } else {
                   
_OnFailure();
                }
                return;
                break;
        }
    }
   
    function
_GetXmlHttpRequest() {
        var
requester
        try
{
           
requester = new XMLHttpRequest();
        }
catch (error) {
           
try {
               
requester = new ActiveXObject("Microsoft.XMLHTTP");
            }
catch (error) {
                return
null;
            }
        }
        return
requester;
    }
}



The code is quiet selfexplanatory. However i have here also an exmaple of the usage. It is very simple.

Here is first the html (yes html file) that will show us our little example:
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
    <
head>
        <
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <
title>Untitled Documenttitle>
        <
script language="javascript" type="text/javascript" src="NIS.RemoteScripter.js">
       
   
   
       

       
   


and here out php script that will supply us with data:
php
header
("Content-type: text/xml");
echo
"h123ohello2asdddo3";
?>


Note the usage of the header. It is very important to identify the data as xml so that the XmlHttpRequest object can use the data in order to be manipulated with the standart DOM methods.


Just create a new javascript file with the name test.js (or whatever you want to) and write following:
// JavaScript Document
////////////////////////////////////////////////////////////
var test = new EzRemoteScripter();
var
div = window.document.getElementById("DataContainer");

//this function is used to find our div element that will
//show all data that is being returned by our wrapper.
function SetDiv() {
    if( !
div) {
       
div = window.document.getElementById("DataContainer");
    }
}

////////////////////////////////////////////////////////////
//here we set the OnUninit event with a function.
//this event is fired if the XmlHttpRequest object was not
//initialized when we call the remote php script.
test.OnUninit         = function() {
   
SetDiv();
   
div.innerHTML = "Uninitialized!!";
}
////////////////////////////////////////////////////////////   
//This event is firing while data is being received from our remote script. Notice that when using document.getElement[..] you have to make sure that the element is set to our variable div.
test.OnLoading         = function() {
   
SetDiv();
   
div.innerHTML = "Loading...";
}
////////////////////////////////////////////////////////////   
//Event is fired when data finished loading
test.OnLoaded         = function() {
   
SetDiv();
   
div.innerHTML = "Loaded...";
}
////////////////////////////////////////////////////////////
//now this event is kinda tricky. Now when finished loading all data resides in the XmlHttpRequest object.
//however when getting the data from the XmlHttpRequest object the OnInteractive event is fired. That means it is the data transfer between the XmlHttpRequest object and your script.
test.OnInteractive     = function() {
   
SetDiv();
   
div.innerHTML = "Interacting...";
}
////////////////////////////////////////////////////////////
//this event is the most used and most important event.
//it is fired if the data has been loaded with a success.
//
test.OnSuccess        = function() {
   
SetDiv();
   
div.innerHTML = "";
       
// here we are getting the data from the XmlHttpRequest object (OnInteractive is being fired)
        //alternatively you may get the data as a string using the test.GetResponseText()
   
var obj = test.GetResponseXML();
    var
books = obj.getElementsByTagName("book");
    for(var
i=0; i < books.length; i++) {
        var
myLI = document.createElement("LI");
       
myLI.innerHTML = books[i].firstChild.data;
       
div.appendChild(myLI);
    }
}
////////////////////////////////////////////////////////////
test.OnFailure         = function() {
   
SetDiv();
   
div.innerHTML = "Failed!";
}
////////////////////////////////////////////////////////////
//this is the funciton that actually calls out php script to get the xml data. pretty easy to use.
//However, you HAVE to init and commit on each call otherwise the script won't work. you may also use the POST method to tranfer data instead of get. To do this you would have to do following:
//d.InitXmlHttpRequest("POST", "test.php");
//d.Commit("myVar=hello&mySecondVar=world");
//
//if you don't want to send any data just pass null to the Commit method. If you leave it empty FireFox will complain.
function Go(d) {
   
d.InitXmlHttpRequest("GET", "test.php");
   
d.Commit(null);
}

How to make income statement while aplying for the visa

   Date Dec 6, 2005


To Whom It May Concern


This is to certify that Mr ........................ and his spouce Mrs. ............., their son Mr. ................. are the permanent resident of ..................(address). They have the following income from various sources.


S. No.
Sources of Income
Proprietor/ Owner
Monthly Income (Nrs.)
Annual Income (Nrs.)
1.
House Rent
Mr .................
5,000.00
60,000.00
2.
Pension
Mr.....................
8,681.00
112,853.00
4
Job Salary
Mr .......................
8,000.00
104,000.00
Mrs ..........................
15,461.53
201.000.00
Total
--.00
In words ----
Exchange Rate: AUD1 = Rs. 54.00
Equivalent to AUD ---
In wods AUD----------------------only


------------
--------------
CA

Vacancy in Dubai

Has been removed because my author copied from other :)

Monday, January 24, 2011

Yesto pani huna sakcha....... A letter from Preetam to computer technician

Yesto pani huna sakcha.......
--------------------------------------------
A letter from Preetam to computer technician
--------------------------------------------
Dear Tech Support,Computer husband joke

Last year I upgraded from Boyfriend 5.0 to Husband 1.0. What I have noticed is a slow down in the performance of the flower and jewellery applications, which had operated flawlessly under the Boyfriend 5.0 system. In addition, Husband 1.0 un-installed many other valuable programs, such as Romance 9.9, but installed undesirable programs such as Sport 7.3, NFL 3.2 and Tennis 4.1. Conversation 8.0 also no longer runs and Housecleaning 2.6 simply crashes the system. I've tried running Nagging 5.3 to fix these problems, but to no avail. What can I do?

Your faithfully

Desperate Preetam

---------------------------

Reply from Tech Support
---------------------------
Dear Desperate Susan,

First, keep in mind that Boyfriend 5.0 was an entertainment package, while Husband 1.0 is an operating system. Try to enter the command C:/I THOUGHT YOU LOVED ME and install Tears 6.2. Husband 1.0 should then automatically run the applications: Guilt 3.3 and Flowers 7.5. But remember, overuse can cause Husband 1.0 to default to such background applications as Grumpy Silence 2.5, Happy Hour 7.0, or Beer 6.1. Please remember that Beer 6.1 is a very bad program that will create Snoring Loudly.WAV files.

DO NOT install Mother-In-Law 1.0 or reinstall another Boyfriend program. These are not supported applications and will crash Husband 1.0. It could also potentially cause Husband 1.0 to default to the program: Girlfriend 9.2, which runs in the background and has been known to introduce viruses into the Operating System.

In summary, Husband 1.0 is a great program, but it does have a limited memory and can't learn new applications quickly. You might consider buying additional software to enhance his system performance. I personally recommend Home Cooking 3.0 and Single Malt Scotch 4.5. Finally consider applications such as Lingerie 6.9 (which has been credited with improved performance of his hardware).

Good Luck

Tech Support

If you have any suggestions for improvements for future releases of this computer software then please post them here.

Monday, January 17, 2011

Ajax Pagination

     
  • Change the file path and the path must be absolute
  •  
  • Change the $qry, where $qry is the query that you want to retrive the data from the database
  •  
  • Change the $starting if you want to change the first starting in most cases it is 0
  •   
  • Change the $recpage the record per page
  •  
  • To change the design change the designpage.php
  •  
  • To change the search form the testpage.php
  •  
  • To change the design of the pagenumber check in the pagination_class.php
  •  
  • No. of pages showing in the left and right side of the current page in the anchors can be changed with the change of the $anchor value at the pagination_class.php
       
  • If you dont like to show the next>>previous>> first >>last link then comment in paginaton_class.php
     
  •  if($previous < 0){
    //$anc .= "
  • First
  • ";
    //$anc .= "
  • Previous
  • ";
    }else{
    //$anc .= "";
    //$anc .= "";
    }


  •     ajax pagination, simple ajax pagination, pagination function in ajax, ajax pagination with files and folders  
       
  •