go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Step 2) Use XMLHttpRequest object to send the request to the target server
 
Subject: Step 2) Use XMLHttpRequest object to send the request to the target server
Author: WebSpider
In response to: Step 1) Create an XMLHttpRequest object
Posted on: 11/10/2009 10:23:33 PM

<script language="javascript">
    XMLHttpRequest xmlhttp = new XMLHttpRequest();
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
</script>


The open() method takes two, three, or five arguments:
      XMLHttpRequest.open(method, url [, async [, user, password]]); 


The first argument defines which method to use when sending the request (GET or POST). The second argument specifies the URL of the server-side script. The third argument specifies that the request should be handled asynchronously or not. The fourth and fifth arguments specify the user and password for authentication if the source is protected.

The send() method takes one argument:
      XMLHttpRequest.send(content); 

If the open() methodÂ’s HTTP retrieval argument is POST, the argument should contain the form data that needs to be send to the server as the follows:
    var url = "myServer.jsp";
    xmlhttp.open("POST", url, true); 
    
    var params = "name1=value1&name2=value2";
	
    //Send the proper header information along with the request
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");
    
    // send out the request
    xmlhttp.send(params);    

If the open methodÂ’s HTTP retrieval argument is GET, simply put null.


 

> On 11/10/2009 10:22:41 PM WebSpider wrote:

<script language="javascript">
function getXmlHttpObject()
{
    if (window.XMLHttpRequest)
    {
        // for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject)
    {
        // for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}
</script>





References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.