Home  >  Article  >  Backend Development  >  php ajax examples and ajax tutorial_PHP tutorial

php ajax examples and ajax tutorial_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:57:53923browse

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.

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;

}


//2 A javascript program that issues asynchronous requests.




function sendrequest()
{

//Get 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"; //Build the requested url address

url = url + "?name=" + user_name;

 
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
}


// 3 A javascript program that handles server responses.


function updatepage()

{
If(xmlhttp.readystate == 4)
{
      var response = xmlhttp.responsetext;
           document.getelementbyid("userinfo").value = response;
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632054.htmlTechArticlephp ajax examples and ajax Tutorial 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 aj...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn