1 Introduction
Web program working principle diagram:
Traditional web program working principle diagram:
2. Core Object
XMLHttpRequest
1. Create objects
Under different browsers, the way to create ajax objects is slightly different.
Under IE:
new ActiveXObject("Microsoft.XMLHTTP")
3. Ajax object related properties and methods:
1. Related methods:
l open(method,url)
Initialize ajax object
method: request method post, get
url: Request resource address
l setRequestHeader(header,value)
Set request header information
Header: header information
Value: value
l send(content)
Send request
Content: The parameters passed only need to be placed here when making a post request
2. Related attributes:
l readyState
Status code of the Ajax object, this status code will change at any time
0: Indicates that the object has been created but not initialized
1: Indicates that the object has been initialized but not sent
2: The send method has been called to make a request
3: Receiving data (part of it received)
4: Reception completed
l onreadystatechange
When the status code of the ajax object changes, the callback function triggered
l status
http response status code
l statusText
Text of http response
l responseText
Text of http response content
l responseXML
xml data of http response content
There are three main ways to transfer Ajax object data:
Text: responseText
Xml: responseXML
Json:responseText