Phpajax instance and ajax tutorial _ PHP Tutorial

Source: Internet
Author: User
Phpajax instance and ajax tutorial. Phpajax instance and ajax tutorial 1 create a JavaScript program for the XMLHttpRequest object. 2. JavaScript program that sends an asynchronous request. 3. JavaScript programs that process server responses. Php Tutorial aj php ajax instance and ajax tutorial 1 create a JavaScript program for the XMLHttpRequest object. 2. JavaScript program that sends an asynchronous request. 3. JavaScript programs that process server responses.

Php Tutorial ajax instance and ajax tutorial
1. create a webpage special effect program for the xmlhttprequest object.
2. javascript program that sends an asynchronous request.
3. javascript programs that process server responses.

*/

// 1 create the javascript program of the xmlhttprequest object.

Function getxmlhttprequest ()
{
Var xmlhttp = null;
Try
{
Xmlhttp = new xmlhttprequest (); // for firefox and other browsers
}
Catch (e)
{
Try
{
Xmlhttp = new activexobject ("msxml2.xmlhttp"); // for IE browsers
}
Catch (e)
{
Try
{
Xmlhttp = new activexobject ("microsoft. xmlhttp ");
}
Catch (e)
{
Xmlhttp = false;
}
}
}

Return xmlhttp;
}


// 2 the javascript program that sends an asynchronous request.

Function sendrequest ()
{
// Obtain the value of the text box name of the page form
Var user_name = document. getelementbyid ("name"). value;

If (user_name = null) | (user_name = ""))
Return;

Xmlhttp = getxmlhttprequest ();
If (xmlhttp = null)
{
Alert ("The browser does not support xmlhttprequest! ");
Return;
}

Var url = "getusername. php"; // Construct the request url
Url = url + "? Name = "+ user_name;

Xmlhttp. open ("get", url, true); // use the get method to open a url connection to prepare for sending a request

// Set a function called after the server processes the request. the function is called updatepage.
Xmlhttp. onreadystatechange = updatepage;
Xmlhttp. send (null); // send a request
}

// 3 the javascript program that processes the server response.

Function updatepage ()
{
If (xmlhttp. readystate = 4)
{
Var response = xmlhttp. responsetext;
Document. getelementbyid ("userinfo"). value = response;
}
}

Http://www.bkjia.com/PHPjc/632054.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632054.htmlTechArticlephp ajax instance with ajax tutorial 1 creates a JavaScript program for the XMLHttpRequest object. 2. JavaScript program that sends an asynchronous request. 3. JavaScript programs that process server responses. Php Tutorial aj...

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.