Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^282) CHAPTER 18 ■ AJAX AND JSON
JavaScript to listen on an input box for a keyup event to be fired. When the event is fired, the
JavaScript communicates the data currently in the search box to the PHP script on the server.
You will use asynchronous mode and the XmlHttpRequest.onreadystatechange event to
wait for the server’s response. If another key is typed while a request is pending, XmlHttpRequest.
abort() will be called and a new request created.
Listings 18-8 and 18-9 show how to create this POST-based Ajax application, which consists of
the suggest.htm and suggest.php files.
Listing 18-8. The POST Client Side (suggest.htm)