xmlhp onreadystatechange func5on if xmlhp readyState 4 xmlhp status 200

Xmlhp onreadystatechange func5on if xmlhp readystate

This preview shows page 14 - 20 out of 25 pages.

xmlh%p . onreadystatechange = func5on (){ if ( xmlh%p . readyState == 4 && xmlh%p . status == 200 ){ } } XMLHttpRequest Object (Properties) //As the server response is ready now, we can define client actions here. a= document . getElementById ("result"); a. innerHTML = xmlhttp . responseText ;
Image of page 14
Example Application: Consider implementing a member registration <form> . After the client has entered the user name, we would like to provide immediate response to the client like “The name is used by other users.” or “You can use this user name” before the registration form is submitted .
Image of page 15
<html> <head> <script <!88 Don’t border the JavaScript now, handle that later!!!! 88> </script> </head> <body> <div id =" responseMessage "></div> <h1> Member registra/on </h1> <form acDon =" memberRegistra/on.php " method =" post "> User Name <input type =" text " id =" userName " name =" userName "/> <br /> Password <input type =" password " name =" userPassword " /> <br /> <input type =" submit " /> </form> </body> </html> Basic HTML code example.html bother >
Image of page 16
AJAX for partial update of the page Step 1. Identify the client event that initiates the request to server. Define the event handler (a JS function) when the event occurs:
Image of page 17
In the event handler, create an XMLHttpRequest object: <script func%on valida%on (){ var xmlh/p ; if (window. XMLH/pRequest ){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlh/p = new XMLH/pRequest (); }else{ // code for IE6, IE5 xmlh/p = new Ac%veXObject (" Microso?.XMLHTTP "); } } </script> The Javascript code in example.html AJAX for partial update of the page >
Image of page 18
AJAX for partial update of the page <script type="text/javascript"> func%on valida%on (){ var xmlh/p ; if (window. XMLH/pRequest ){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlh/p = new XMLH/pRequest (); }else{ // code for IE6, IE5 xmlh/p = new Ac%veXObject (" Microso?.XMLHTTP "); } xmlh/p . onreadystatechange = func%on (){ if ( xmlh/p . readyState == 4 && xmlh/p . status == 200 ){ } } } </script> The Javascript code in example.html
Image of page 19
Image of page 20

You've reached the end of your free preview.

Want to read all 25 pages?

  • Fall '13
  • Dr. C. Wu
  • Ajax

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture