ajax object. Synchronization request and asynchronous transmission ajax

ajax object properties, methods

 Attributes

  • readyState: Ajax state code * 0: the object has been created, but not initialized, but new successfully acquired the object, but did not call the open method 1: represents an object has been initialized, but not send, call the open method, but the send method is not called 2: a method call to send a request to 3: is receiving data (receiving portion), the client has received the returned data portion 4: reception is completed, the client has received all the data *

  • status: http response status code 200 delegates successfully acquired server-side data 404 page not found, and so on ......

  • statusText: http response status text

  • responseText: If the server returns the string, using the reception responseText

  • responseXML: If the server returns XML data reception using responseXML

  • onreadystatechange: readyState status code when triggered by changes callback

method

  • open (method, url, [aycs ]): Ajax object initialization (open) Method: HTTP request method, GET / POST URL: server address request aycs: synchronous and asynchronous

 

  • setRequestHeader (header, value): header information setting request header: request header name value: request header of

 

  • xhr.getAllResponseHeaders () Get all the response headers

  • xhr.getResponseHeader ( 'key') assigned to the first information acquired

  • send ([content]): Ajax requests content: If a get request, this parameter is null;

    If the data is post request, this parameter is to pass

 

Synchronous and asynchronous

for example:

Xiao Ming go to a restaurant line up to order, the clerk will Xiaoming menu to tell the chef for production, this time queuing behind Xiaoming who have been waiting, until the chef finished, the meals to the hands of Xiao Ming left behind the people to continue meal; this is the synchronization;

However, if the clerk would Xiaoming menu to tell the chef, the waiter sent Bob a number plate to the side to wait behind people who continue to order, the chef will Xiaoming meals do any time after calling Xiao Ming meals; this is the asynchronous processing.

ajax request is sent asynchronously process by default, when each step is performed does not consider whether executing the last step, the last step just started, and that is the server receives a message, name next step is to begin, but you can set the open the third parameter () method is used to set the synchronous or asynchronous;

ajax transmission request

The content of the input of the input box, determining whether the input content is available (admin unavailable, other available)

html file:

 

Js file server:

 

By http://127.0.0.1:8888/ access html pages, when the input box loses focus, the triggering event, send a request to the server, to determine whether the content is available.

 

Guess you like

Origin www.cnblogs.com/ruoruchujian/p/10982419.html