ajax+php Quick Start and simple application notes _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.