Step 4 Define the response actions when the servers response is received code

Step 4 define the response actions when the servers

This preview shows page 19 - 24 out of 25 pages.

Step 4. Define the response actions when the server’s response is received: code for modern browsers
Image of page 19
Define the response actions when the server’s response is received: code for modern browsers
Image of page 20
Define the request that is sent “behind the scenes” The request will send the userName value to valida%on.php, which can access it using $ _GET [ 'userName ']. code for modern browsers
Image of page 21
Send the request AJAX for partial update of the page DONE!! <script> function validation (){ var xmlhttp ; if (window. XMLHttpRequest ){ // code for modern browsers xmlhttp = new XMLHttpRequest (); }else{ // code for old IE browsers xmlhttp = new ActiveXObject (" Microsoft.XMLHTTP "); } xmlhttp . onreadystatechange = function (){ if ( xmlhttp . readyState == 4 && xmlhttp . status == 200 ){ document. getElementById (" responseMessage "). innerHTML = xmlhttp . responseText ; } } a = document. getElementById (" userName "); xmlhttp . open (" GET "," validation.php?userName= "+ a . value , true); } </script> The Javascript code in example.html
Image of page 22
PHP code on the server Output generated by valida1on.php Now, create validation.php for responding to the AJAX request.
Image of page 23
Image of page 24

You've reached the end of your free preview.

Want to read all 25 pages?

  • Fall '13
  • Dr. C. Wu
  • Ajax, Web page, World Wide Web, Web server

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture