Home > Article > Backend Development > php ajax examples and ajax tutorial_PHP tutorial
php ajax examples and ajax tutorials 1. Create a JavaScript program for XMLHttpRequest objects. 2 A JavaScript program that makes asynchronous requests. 3. JavaScript program that handles server response.
php tutorial ajax examples and ajax tutorial
1. Create a web page special effects program for the xmlhttprequest object.
2 A javascript program that makes asynchronous requests.
3 javascript program that handles server response.
*/
//1Javascript program that creates xmlhttprequest object.
//2 A javascript program that issues asynchronous requests.function getxmlhttprequest()
}
{
var xmlhttp=null;
Try
{
}
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;
{//Get the value of the text box name of the page form
return;
var user_name = document.getelementbyid("name").value;
if((user_name == null) || (user_name == ""))url = url + "?name=" + user_name;
xmlhttp = getxmlhttprequest();
If(xmlhttp == null)
{
alert("The browser does not support xmlhttprequest!");
return;
}
var url = "getusername.php"; //Build the requested url address// 3 A javascript program that handles server responses.
xmlhttp.open("get", url, true); //Use the get method to open a connection to the url to prepare for making a request
//Set a function to be called after the server has processed the request. The function is called updatepage
xmlhttp.onreadystatechange = updatepage;
xmlhttp.send(null); //Send request
}
function updatepage()
If(xmlhttp.readystate == 4)
{
var response = xmlhttp.responsetext;
document.getelementbyid("userinfo").value = response;
}
}