# Connection Manager GET Transaction

To construct a GET transaction using the Connection Manager, you will need to construct a querystring of key-value pairs and append it to the URL. The following code example provides a step-by-step approach to creating a simple GET transaction.

### Source file and dependencies

Load the YAHOO namespace and connection manager source file:

    <script src="yahoo.js"></script>
    <script src="connection.js"></script>

### Assemble the Querystring

Construct a querystring with two key-value pairs of username = anonymous and userid = 0:

      /*
       *
       * Create a querystring with example key-value pairs of
       * username and userid.  Remember to encode the querystring
       * if and when the string contains special characters.
       *
       */
      var sUrl = "get.php?username=anonymous&userid=0";

### The Callback Object

Create a callback object to handle the response, and pass an object literal to both success and failure as the argument.

    var handleSuccess = function(o){

    	function parseHeaders(){
    		var allHeaders = headerStr.split("\n");
    		var headers;
    		for(var i=0; i < headers.length; i++){
    			var delimitPos = header[i].indexOf(':');
    			if(delimitPos != -1){
    				headers[i] = "<p>" +
    				headers[i].substring(0,delimitPos) + ":"+
    				headers[i].substring(delimitPos+1) + "</p>";
    			}
    		return headers;
    	}

    	if(o.responseText !== undefined){
    		div.innerHTML = "Transaction id: " + o.tId;
    		div.innerHTML += "HTTP status: " + o.status;
    		div.innerHTML += "Status code message: " + o.statusText;
    		div.innerHTML += "HTTP headers: " + parseHeaders();
    		div.innerHTML += "Server response: " + o.responseText;
    		div.innerHTML += "Argument object: property foo = " + o.argument.foo +
    						 "and property bar = " + o.argument.bar;
    	}
    }

    var callback =
    {
      success:handleSuccess,
      failure: handleFailure
      argument: { foo:"foo", bar:"bar" }
    };

### Initiate the GET Transaction

Call YAHOO.util.Connect.asyncRequest to send the request to get.php, and the PHP file will return the output of $_POST via print_r(). The handleSuccess callback will print the response object's properties, including the server response data.

Note: Caching and GET idempotency.

    var request = YAHOO.util.Connection.asyncRequest('GET', sUrl, callback);