Quick start and simple application of Ajax + PHP _ PHP-php Tutorial

Source: Internet
Author: User
For Ajax, the core object is XMLHttpRequest. all Ajax operations cannot be separated from the operations on this object.

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:

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.