1 Introduction
Web program working principle diagram:
Traditional web program working principle diagram:
Ajax working principle diagram:
1. About Ajax
l Asynchronous
l JavaScript
l And
l XML
Ajax is a technology that uses javascript to interact with xml and the server
Xml:
Json:
2. Development history
l was born in 1998
l 2005 Popular
3. Running platform
l Google Chrome
l Mozilla
l Firefox
l Internet Explorer
l Opera
l Konqueror
l Safari
2. Core objects
XMLHttpRequest
1. Create objects
Under different browsers, the way to create ajax objects is slightly different.
Under IE:
new ActiveXObject("Microsoft.XMLHTTP")
w3c model browser:
new XMLHttpRequest()
5. Encapsulate ajax
Call code:
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 a request
Content: The passed parameters need to be placed here only when making a post request
2. Related attributes:
l readyState
The 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
The callback function triggered when the status code of the ajax object changes
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
The above introduces ajax1-php (27), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.