Prev | Current Page 116 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

value)" /> #2
#3




(annotation)<#1 Simple styling>
(annotation)<#2 onkeyup event is used so that checkUsername() is called on every keystroke>
(annotation)<#3 Placeholder for message returned by server>
This is a simple form that uses the onkeyup event on the input field to send the current text that the user
has entered to the PHP file on the server. This is done in the JavaScript check() function which is stored in a
separate JavaScript file called ajax.js as shown in Listing 4.3.
Listing 4.3: Hand crafted JavaScript code to call back to the server for validation
var request;
if (navigator.appName == "Microsoft Internet Explorer") { |#1
request = new ActiveXObject("Microsoft.XMLHTTP"); |
} else { |
request = new XMLHttpRequest(); |
}
function checkUsername(username)
{
var success = 4;
request.abort();
request.open("GET", "ajax1.php?name=" + username, true); |#2
request.onreadystatechange=function() { |#3
if (request.readyState == success) { |#4
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
document.getElementById('message').innerHTML
= request.responseText;
}
}
request.


Pages:
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
opony goodyear karta kredytowa millenium House Extension London zakłady bukmacherskie Potopek