::::::::::::::::::::::::::
Home
Home Page
Method of generation of a code
Displays
Result of binding of the data
Systems of patterns of pages
Data acquisition without use XML
Data acquisition without use XML
Use JSON on the party of the client
Improved online shop
Review Ajax
Departure XMLHttpRequest
Processing of search servleta
 The search processing with help JavaScript
Problems of use Ajax
As it was more than once spoken, organization W3C is engaged mainly in development and creation of b
OASIS
Hands off PHP!
Automatic redirect (Auto Redirect) on PHP
Breaking of passwords becomes more accessible
Web2.0 Layout
Links
:::::::::::::::::::::::::

 

The search processing with help JavaScript


readyState property XMLHttpRequest - numerical value which defines{determines} the status of a cycle of search. It changes from 0 for "uncertain" and up to 4 for "completed". Each time when varies readyState, appears event readystatechange and the operator is caused with the help onreadystatechange properties.


In listing 3 you have seen, how function getReadyStateHandler () for creation of the operator was caused. This operator then is attributed to property onreadystatechange. getReadyStateHandler () used that fact, that functions - objects of the first class in JavaScript. It designates, that functions can be parameters to other functions and can create and return values of other functions also. To a duty getReadyStateHandler () - to return value of function which checks, whether has come to the end XMLHttpRequest and whether the answer in a XML-format in the operator determined by a call has been sent. Listing 6 - a code for getReadyStateHandler ().


Listing 6. Function getReadyStateHandler ().



/*

                        * Returns function which expects that has ended

                        * Certain{Determined} XMLHttpRequest, then passes his{its} answer in a XML-format

                        * To the set operator * req is XMLHttpRequest, whose status changes

                        * responseXmlHandler - the function, transmitted search XML

                        */

                        function getReadyStateHandler (req, responseXmlHandler) {


// Returns uncertain function which reads out

// Data XMLHttpRequest return function () {


// If the status is required "is finished"

if (req.readyState == 4) {


// We check, whether there has come the successful answer of the server

if (req.status == 200) {


// Passes XML to the operator

responseXmlHandler (req.responseXML);


} else {


// There was mistake HTTP

alert (" HTTP error: " +req.status);

}

}

}

}