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...