Google


ADBRITE ads links
You are here: CodeIdol.com > Ajax > Head Rush Ajax > She Blinded Me With Asynchronous > Writing The Callback Function

SAVE
Digg
Shown on del.icio.us del.icio.us
See Whos Talking About This on Technorati Technorati
I've Reddit reddit

3.22. Writing the callback function

The only function left to write is serveDrink(), which needs to take the response from the server and figure out who placed the order, and which coffee maker was used to brew the order. Then serveDrink() can set the coffee maker's status to "Idle" and let the person who placed the order know that their coffee is ready.

Let's start by checking the ready state, the HTTP status code, and then getting the response from the server.

    function serveDrink() {
      if (request.readyState == 4) {
        if (request.status == 200) {
        var response = request.responseText;

       // Figure out who placed the order, and
       // which coffee maker was used
    } else
       alert("Error! Request status is " + request.status);
    }
 }
All of this code should be pretty familiar by now. You'll use this same code in almost
every callback function you ever write.


SAVE
Digg
Shown on del.icio.us del.icio.us
See Whos Talking About This on Technorati Technorati
I've Reddit reddit

You are here: CodeIdol.com > Ajax > Head Rush Ajax > She Blinded Me With Asynchronous > Writing The Callback Function
   
Related tags







Popular Categories
Unix books and guides
AJAX popular information
C# language guides
Windows books and cookbooks
.......






© CodeIdol Labs, 2007