PHP Ajax Examples and AJAX tutorial 1 create JavaScript programs for XMLHttpRequest objects. 2 the JavaScript program that issued the asynchronous request. 3 a JavaScript program that handles server responses.
PHP Tutorial Ajax Examples and Ajax tutorials
1 Create a Web effect program for XMLHttpRequest objects.
2 the JavaScript program that issued the asynchronous request.
3 a JavaScript program that handles server responses.
*/
1 Create a JavaScript program for the XMLHttpRequest object.
function Getxmlhttprequest ()
{
var xmlhttp=null;
Try
{
XMLHTTP = new XMLHttpRequest (); For browsers such as Firefox
}
catch (E)
{
Try
{
XMLHTTP = new ActiveXObject ("Msxml2.xmlhttp"); For IE browser
}
catch (E)
{
Try
{
XMLHTTP = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (E)
{
XMLHTTP = false;
}
}
}
return XMLHTTP;
}
2 the JavaScript program that issued the asynchronous request.
function SendRequest ()
{
Gets the value of the text box name for the page form
var user_name = document.getElementById ("name"). Value;
if ((user_name = = null) | | (user_name = = ""))
Return
XMLHTTP = Getxmlhttprequest ();
if (xmlhttp = = null)
{
Alert ("Browser does not support xmlhttprequest! ");
Return
}
var url = "getusername.php"; URL address of the build request
url = url + "? name=" + user_name;
Xmlhttp.open ("Get", url, True); Use the Get method to open a connection to a URL to prepare for making a request
Set a function that is called when the server finishes processing the request, and the function is named Updatepage
Xmlhttp.onreadystatechange = Updatepage;
Xmlhttp.send (NULL); Send Request
}
3 a JavaScript program that handles server responses.
function Updatepage ()
{
if (xmlhttp.readystate = = 4)
{
var response = Xmlhttp.responsetext;
document.getElementById ("UserInfo"). Value = response;
}
}
http://www.bkjia.com/PHPjc/632054.html www.bkjia.com true http://www.bkjia.com/PHPjc/632054.html techarticle PHP ajax Examples and AJAX tutorial 1 create JavaScript programs for XMLHttpRequest objects. 2 the JavaScript program that issued the asynchronous request. 3 a JavaScript program that handles server responses. PHP Tutorial AJ ...