Section 2.30. Checking the ready state


2.30. Checking the ready state

Now that you've got getCustomerInfo() working, and the browser knows to call updatePage() when the request's ready state changes, it's time to write the callback function for the Break Neck app. Let's start out by checking that ready state, and making sure the request has been completed before doing anything to the HTML.

Add a new function to your pizza.html file, called updatePage(), and start with this code:

     function updatePage() {You HAVE to make sure the name of this function matches up to the function name you assigned to onreadystatechange in getCustomerInfo().       if (request.readyState == 4) {This if statement makes sure that none of the rest of the code runs unless the ready state is "4", which means the server's finished, and it's safe to use the response data.         /* Get the response from the server */Remember, you declared the request variable in your static JavaScript, so any function can use it.         /* Update the order form */You'll write code to take care of both of these things over the next few pages.       }     } 




Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net