YUI recommends YUI 3.
YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.
To create a GET transaction using 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.
Click "Send a GET Request" below to try it out, then read the description below to learn how to create a simple transaction using Connection Manager.
Load the Yahoo Global Object and Connection Manager source files:
1 | <script src="yahoo.js"></script> |
2 | <script src="event.js"></script> |
3 | <script src="connection.js"></script> |
view plain | print | ? |
Construct a querystring with two key-value pairs of username = anonymous
and userid = 0
:
1 | /* |
2 | * |
3 | * Create a querystring with example key-value pairs of |
4 | * username and userid. Remember to encode the querystring |
5 | * if and when the string contains special characters. |
6 | * |
7 | */ |
8 | var sUrl = "php/get.php?username=anonymous&userid=0"; |
view plain | print | ? |
Create a callback object to handle the response, and pass an object literal to both success
and failure
handlers as the argument.
1 | var div = document.getElementById('container'); |
2 | |
3 | var handleSuccess = function(o){ |
4 | if(o.responseText !== undefined){ |
5 | div.innerHTML = "<li>Transaction id: " + o.tId + "</li>"; |
6 | div.innerHTML += "<li>HTTP status: " + o.status + "</li>"; |
7 | div.innerHTML += "<li>Status code message: " + o.statusText + "</li>"; |
8 | div.innerHTML += "<li>HTTP headers: <ul>" + o.getAllResponseHeaders + "</ul></li>"; |
9 | div.innerHTML += "<li>Server response: " + o.responseText + "</li>"; |
10 | div.innerHTML += "<li>Argument object: Object ( [foo] => " + o.argument.foo + |
11 | " [bar] => " + o.argument.bar +" )</li>"; |
12 | } |
13 | } |
14 | |
15 | var handleFailure = function(o){ |
16 | if(o.responseText !== undefined){ |
17 | div.innerHTML = "<li>Transaction id: " + o.tId + "</li>"; |
18 | div.innerHTML += "<li>HTTP status: " + o.status + "</li>"; |
19 | div.innerHTML += "<li>Status code message: " + o.statusText + "</li>"; |
20 | } |
21 | } |
22 | |
23 | var callback = |
24 | { |
25 | success:handleSuccess, |
26 | failure: handleFailure, |
27 | argument: { foo:"foo", bar:"bar" } |
28 | }; |
view plain | print | ? |
Call YAHOO.util.Connect.asyncRequest
to send the request to get.php
,
and the PHP file will return the readable output of $_GET
via print_r()
.
The handleSuccess
callback will print the response object's properties, including
the server response data.
1 | var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback); |
view plain | print | ? |
You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.
Note: Logging and debugging is currently turned off for this example.
Copyright © 2011 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings