Brief introduction:
Ajax is made up of HTML, javascript™ technology, DHTML, and DOM, an excellent way to turn a clumsy web interface into an interactive Ajax application.
For Ajax, one of the core objects is XMLHttpRequest, and all AJAX operations are inseparable from the operation of this object.
Create a XMLHttpRequest Object
For IE Browser:
Copy the Code code as follows:
XmlHttp = new ActiveXObject (' microsoft.xmlhttp ');
For other browsers:
Copy the Code code as follows:
XmlHttp = new XMLHttpRequest ();
Different browsers support the XMLHttpRequest object in JavaScript, so you need to make a decision based on the situation.
XMLHttpRequest Object-related methods
Open Request
Copy CodeThe code is as follows:
Xmlhttprequest.open (delivery method, address, whether asynchronous request)
Ready to execute
Copy CodeThe code is as follows:
Xmlhttprequest.onreadystatechange
Get execution results
Copy CodeThe code is as follows:
Xmlhttprequest.responsetext
An example of a simple php+ajax:
The first is the Test.js file:
Copy CodeThe 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 is the PHP operation file, do.php
Copy CodeThe code is as follows:
$id =@$_get[id];
for ($i =1; $i <10; $i + +) {
echo $id;
}
Then the front-end display page, test.html
Copy CodeThe code is as follows:
1 | |
2 | |
3
http://www.bkjia.com/PHPjc/328102.html www.bkjia.com true http://www.bkjia.com/PHPjc/328102.html techarticle Summary: Ajax consists of HTML, JavaScript technology, DHTML, and DOM, an excellent way to turn a clumsy web interface into an interactive AJAX application. For Ajax, the most core ...