Ajax + PHP quick start and simple application instructions. Introduction: Ajax is composed of HTML, JavaScript technology, DHTML, and DOM. this outstanding method can convert clumsy Web interfaces into interactive Ajax applications. For Ajax, the core
Introduction:
Ajax consists of HTML, JavaScript™The combination of technology, DHTML and DOM can transform clumsy Web interfaces into interactive Ajax applications.
For Ajax, the core object is XMLHttpRequest. all Ajax operations cannot be separated from operations on this object.
Create an XMLHttpRequest object
For IE browsers:
The code is as follows:
XmlHttp = new ActiveXObject ('Microsoft. xmlhttp ');
For other browsers:
The code is as follows:
XmlHttp = new XMLHttpRequest ();
Different browsers have different support for XMLHttpRequest objects in javascript, so you need to make a judgment based on the situation.
XMLHttpRequest object Related methods
Open request
The code is as follows:
XMLHttpRequest. open (transfer method, address, asynchronous request or not)
Ready for execution
The code is as follows:
XMLHttpRequest. onreadystatechange
Obtain execution results
The code is as follows:
XMLHttpRequest. responseText
A simple php + Ajax example:
The first is the test. js file:
The code is as follows:
Var xmlHttp;
Function S_xmlhttprequest (){
If (window. ActiveXObject ){
XmlHttp = new ActiveXObject ('Microsoft. xmlhttp ');
} Else if (window. XMLHttpRequest ){
XmlHttp = new XMLHttpRequest ();
}
}
Function php100 (url ){
S_xmlhttprequest ();
XmlHttp. open ("GET", "do. php? Id = "+ url, true );
XmlHttp. onreadystatechange = byphp;
XmlHttp. send (null );
}
Function byphp (){
Var byphp100 = xmlHttp. responseText;
Document. getElementById ('php100'). innerHTML = byphp100;
}
Then the file that executes the php operation, do. php
The code is as follows:
$ Id = @ $ _ GET [id];
For ($ I = 1; $ I <10; $ I ++ ){
Echo $ id;
}
The frontend display page, test.html
The code is as follows: