source: cows/branches/cows-vis/cows/pylons/project_templates/cows_server/+package+/public/js/yui/examples/io/io-post.html @ 5259

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/branches/cows-vis/cows/pylons/project_templates/cows_server/+package+/public/js/yui/examples/io/io-post.html@5259
Revision 5259, 16.8 KB checked in by domlowe, 11 years ago (diff)

adding yui javascript

Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2<html>
3<head>
4        <title>YUI Library Examples: IO Utility: POST Transaction</title>
5    <meta http-equiv="content-type" content="text/html; charset=utf-8">
6        <link rel="stylesheet" type="text/css" href="../../assets/yui.css" >
7
8<style>
9    /*Supplemental CSS for the YUI distribution*/
10    #custom-doc { width: 95%; min-width: 950px; }
11    #pagetitle {background-image: url(../../assets/bg_hd.gif);}
12    #pagetitle h1 {background-image: url(../../assets/title_h_bg.gif);}
13</style>
14
15<link rel="stylesheet" type="text/css" href="../../assets/dpSyntaxHighlighter.css">
16<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
17<script type="text/javascript" src="../../build/yui/yui-min.js"></script>
18<style type="text/css">
19#container li {margin-left:2em;}
20#container { background-color:#FFFFFF; border:1px dotted #666666; padding:1em; margin-bottom:1em;}
21</style>
22
23
24</head>
25<body id="yahoo-com" class=" yui-skin-sam">
26<div id="custom-doc" class="yui-t2">
27<div id="hd">
28        <div id="ygunav">
29                <p>
30            <em>
31                <a href="http://developer.yahoo.com/yui/3/">YUI 3.x Home</a> <i> - </i> 
32            </em>
33                </p>
34                <form action="http://search.yahoo.com/search" id="sitesearchform">
35            <input name="vs" type="hidden" value="developer.yahoo.com">
36            <input name="vs" type="hidden" value="yuiblog.com">
37                    <div id="sitesearch">
38                        <label for="searchinput">Site Search (YDN &amp; YUIBlog): </label>
39                            <input type="text" id="searchinput" name="p">
40                            <input type="submit" value="Search" id="searchsubmit" class="ygbt">
41                    </div>
42                </form>
43    </div>
44        <div id="ygma"><a href="../../"><img src="../../assets/logo.gif"  border="0" width="200" height="93"></a></div>
45        <div id="pagetitle"><h1>YUI Library Examples: IO Utility: POST Transaction</h1></div>
46</div>
47<div id="bd">
48
49        <div id="bar-note"><p><strong>Note:</strong> This is YUI 3.x. Looking for <a href="http://developer.yahoo.com/yui/">YUI 2.x</a>?</p></div>
50
51        <div id="yui-main">
52                <div class="yui-b">
53                  <div class="yui-ge">
54                          <div class="yui-u first example" id="main">
55
56        <h2>IO Utility: POST Transaction</h2>
57
58        <div id="example" class="promo">
59        <p>
60        <p>POSTing data to a server using YUI's IO utility is a simple process.  Click "Send a POST Request" below to try it out, then read the description below to learn how it's done.</p>   </p>   
61
62        <div class="module example-container ">
63                        <div class="hd exampleHd">
64                        <p class="newWindowButton yui-skin-sam">
65                <a href="io-post_clean.html" target="_blank">View example in new window.</a>
66            </p>
67                </div>          <div id="example-canvas" class="bd">
68
69               
70        <!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->
71       
72        <div id="container">
73        <ul>
74        <li>IO POST response data will appear here.</li>
75    </ul>
76</div>
77<form><input type="button" id="requestButton" value="Send a POST Request"></form>
78
79<script>
80
81YUI({base:"../../build/", timeout: 10000}).use("io",
82
83        function(Y) {
84
85                //Get a reference to the Node that we are using
86                //to report results:
87                var div = Y.Node.get('#container ul');
88
89                //A function handler to use for successful requests:
90                var handleSuccess = function(ioId, o){
91                        Y.log(arguments);
92                        Y.log("The success handler was called.  Id: " + ioId + ".", "info", "example");
93
94                        if(o.responseText !== undefined){
95                                var s = "<li>Transaction id: " + ioId + "</li>";
96                                s += "<li>HTTP status: " + o.status + "</li>";
97                                s += "<li>Status code message: " + o.statusText + "</li>";
98                                s += "<li>HTTP headers received: <ul>" + o.getAllResponseHeaders() + "</ul></li>";
99                                s += "<li>PHP response: " + o.responseText + "</li>";
100                                div.set("innerHTML", s);
101                        }
102                }
103
104                //A function handler to use for failed requests:
105                var handleFailure = function(ioId, o){
106                        Y.log("The failure handler was called.  Id: " + ioId + ".", "info", "example");
107
108                        if(o.responseText !== undefined){
109                                var s = "<li>Transaction id: " + ioId + "</li>";
110                                s += "<li>HTTP status: " + o.status + "</li>";
111                                s += "<li>Status code message: " + o.statusText + "</li>";
112                                div.set("innerHTML", s);
113                        }
114                }
115
116                //Subscribe our handlers to IO's global custom events:
117                Y.on('io:success', handleSuccess);
118                Y.on('io:failure', handleFailure);
119
120
121                /* Configuration object for POST transaction */
122                var cfg = {
123                        method: "POST",
124                        data: "user=YDN&password=API",
125                        headers: { 'X-Transaction': 'POST Example'}
126                };
127
128                //The URL of the resource to which we're POSTing data:
129                var sUrl = "assets/post.php";
130
131                //Handler to make our XHR request when the button is clicked:
132                function makeRequest(){
133
134                        div.set("innerHTML", "Loading data from new request...");
135
136                        var request = Y.io(sUrl, cfg);
137                        Y.log("Initiating request; Id: " + request.id + ".", "info", "example");
138
139                }
140
141                // Make a request when the button is clicked:
142                Y.on("click", makeRequest, "#requestButton");
143
144                Y.log("As you interact with this example, relevant steps in the process will be logged here.", "info", "example");
145        }
146);
147</script>
148
149       
150        <!--END SOURCE CODE FOR EXAMPLE =============================== -->
151       
152               
153                </div>
154        </div>                 
155        </div>
156               
157        <h2 class="first">Using IO to Post Data and Receive the Server Response via HTTP POST</h2>
158
159<h3>Create a YUI Instance</h3>
160<p>Create a YUI instance, using IO, for this example:</p>
161
162<textarea name="code" class="JScript" cols="60" rows="1">
163//Create a YUI instance including support for IO:
164YUI({base:"../../build/", timeout: 10000}).use("io", function(Y) {
165        // Y is the YUI instance.
166        // The rest of the following code is encapsulated in this
167        // anonymous function.
168} );
169</textarea>
170
171<h3>Assemble a Configuration Object for a POST Transaction</h3>
172<p>The IO configuration object support allows you to designate the transaction method (<code>POST</code> in this case) and other information, including data that should be sent as the POST body:</p>
173
174<textarea name="code" class="JScript" cols="60" rows="1">/* Configuration object for POST transaction */
175var cfg = {
176    method: "POST",
177    data: "user=YDN&password=API",
178    headers: { 'X-Transaction': 'POST Example'},
179};</textarea>
180
181<h3>Create Handlers to Process Successful and Unsuccessful Transactions</h3>
182
183<p>Our handlers for the events that fire on successful and unsuccessful responses will write out information about the transaction to the <code>innerHTML</code> of an element on the page:</p>
184
185<textarea name="code" class="JScript" cols="60" rows="1">//Get a reference to the Node that we are using
186//to report results:
187var div = Y.Node.get('#container');
188
189//A function handler to use for successful requests:
190var handleSuccess = function(ioId, o){
191    Y.log(arguments);
192    Y.log("The success handler was called.  Id: " + ioId + ".", "info", "example");
193
194    if(o.responseText !== undefined){
195        var s = "<li>Transaction id: " + ioId + "</li>";
196        s += "<li>HTTP status: " + o.status + "</li>";
197        s += "<li>Status code message: " + o.statusText + "</li>";
198        s += "<li>HTTP headers received: <ul>" + o.getAllResponseHeaders() + "</ul></li>";
199        s += "<li>PHP response: " + o.responseText + "</li>";
200        div.set("innerHTML", s);
201    }
202};
203
204//A function handler to use for failed requests:
205var handleFailure = function(ioId, o){
206    Y.log("The failure handler was called.  Id: " + ioId + ".", "info", "example");
207
208    if(o.responseText !== undefined){
209        var s = "<li>Transaction id: " + ioId + "</li>";
210        s += "<li>HTTP status: " + o.status + "</li>";
211        s += "<li>Status code message: " + o.statusText + "</li>";
212        div.set("innerHTML", s);
213    }
214};
215
216//Subscribe our handlers to IO's global custom events:
217Y.on('io:success', handleSuccess);
218Y.on('io:failure', handleFailure);</textarea>
219
220<h3>Initiate the POST Transaction</h3>
221<p>
222The final step in this example is to start the IO POST transaction when a button on the page is clicked.  We have a button with an ID of <code>makeRequest</code>; we wire that button to the IO request with the following code:
223</p>
224
225<textarea name="code" class="JScript" cols="60" rows="1">//Handler to make our XHR request when the button is clicked:
226function makeRequest(){
227
228    div.set("innerHTML", "Loading data from new request...");
229
230    var request = Y.io(sUrl, cfg);
231    Y.log("Initiating request; Id: " + request.id + ".", "info", "example");
232
233}
234
235// Make a request when the button is clicked:
236Y.on("click", makeRequest, "#requestButton");</textarea>
237
238<h3>Full Code</h3>
239
240<p>The full JavaScript code for this example follows:</p>
241
242<textarea name="code" class="JScript" cols="60" rows="1">
243YUI({base:"../../build/", timeout: 10000}).use("io",
244
245        function(Y) {
246
247                //Get a reference to the Node that we are using
248                //to report results:
249                var div = Y.Node.get('#container');
250
251                //A function handler to use for successful requests:
252                var handleSuccess = function(ioId, o){
253                        Y.log(arguments);
254                        Y.log("The success handler was called.  Id: " + ioId + ".", "info", "example");
255
256                        if(o.responseText !== undefined){
257                                var s = "<li>Transaction id: " + ioId + "</li>";
258                                s += "<li>HTTP status: " + o.status + "</li>";
259                                s += "<li>Status code message: " + o.statusText + "</li>";
260                                s += "<li>HTTP headers received: <ul>" + o.getAllResponseHeaders() + "</ul></li>";
261                                s += "<li>PHP response: " + o.responseText + "</li>";
262                                div.set("innerHTML", s);
263                        }
264                };
265
266                //A function handler to use for failed requests:
267                var handleFailure = function(ioId, o){
268                        Y.log("The failure handler was called.  Id: " + ioId + ".", "info", "example");
269
270                        if(o.responseText !== undefined){
271                                var s = "<li>Transaction id: " + ioId + "</li>";
272                                s += "<li>HTTP status: " + o.status + "</li>";
273                                s += "<li>Status code message: " + o.statusText + "</li>";
274                                div.set("innerHTML", s);
275                        }
276                };
277
278                //Subscribe our handlers to IO's global custom events:
279                Y.on('io:success', handleSuccess);
280                Y.on('io:failure', handleFailure);
281
282
283                /* Configuration object for POST transaction */
284                var cfg = {
285                        method: "POST",
286                        data: "user=YDN&password=API",
287                        headers: { 'X-Transaction': 'POST Example'},
288                };
289
290                //The URL of the resource to which we're POSTing data:
291                var sUrl = "assets/post.php";
292
293                //Handler to make our XHR request when the button is clicked:
294                function makeRequest(){
295
296                        div.set("innerHTML", "Loading data from new request...");
297
298                        var request = Y.io(sUrl, cfg);
299                        Y.log("Initiating request; Id: " + request.id + ".", "info", "example");
300
301                }
302
303                // Make a request when the button is clicked:
304                Y.on("click", makeRequest, "#requestButton");
305
306                Y.log("As you interact with this example, relevant steps in the process will be logged here.", "info", "example");
307        }
308);</textarea>                           </div>
309                                <div class="yui-u sidebar">
310                                       
311                               
312                                        <div id="examples" class="mod box4">
313                        <div class="hd">
314                                                <h4>
315    IO Utility Examples:</h4>
316                        </div>
317                                                <div class="bd">
318                                                        <ul>
319                                                                <li class='selected'><a href='../io/io-post.html'>POST Transaction</a></li><li><a href='../io/io-weather.html'>XML Transaction &mdash; Retrieving a Yahoo! Weather RSS (XML) Feed via a Server-Side Proxy</a></li><li><a href='../io/io-xdr.html'>Cross-Domain JSON Transaction &mdash; Retrieving a News Feed from Yahoo! Pipes</a></li>                                                       </ul>
320                                                </div>
321                                        </div>
322                                       
323                                        <div class="mod box4">
324                        <div class="hd">
325                                                <h4>More IO Utility Resources:</h4>
326                        </div>
327                        <div class="bd">
328                                                <ul>
329                                                        <!-- <li><a href="http://developer.yahoo.com/yui/io/">User's Guide</a> (external)</li> -->
330                                                <li><a href="../../api/module_io.html">API Documentation</a></li>
331</ul>
332                        </div>
333                                        </div>
334                          </div>
335                </div>
336               
337                </div>
338        </div>
339
340
341<div class="yui-b toc3" id="tocWrapper">
342<!-- TABLE OF CONTENTS -->
343<div id="toc">
344       
345<ul>
346<li class="sect first">YUI 3.x Project</li><li class="item"><a title="The Yahoo! User Interface (YUI) Library, 3.x Branch, " href="http://developer.yahoo.com/yui/3/">YUI 3 Web Site (external)</a></li><li class="item"><a title="Examples of every YUI utility and control in action" href="../../examples/">YUI 3 Examples</a></li><li class="item"><a title="Instantly searchable API documentation for the entire YUI library." href="../../api/">YUI 3 API Docs</a></li><li class="item"><a title="The YUI Library can be downloaded from SourceForge" href="http://sourceforge.net/projects/yui/">YUI 3 on Sourceforge (external)</a></li><li class="item"><a title="YUI is free and open, offered under a BSD license." href="http://developer.yahoo.com/yui/3/license.html">YUI License (external)</a></li><li class="sect">YUI 3 Core - Examples</li><li class="item"><a title="YUI (Global Prerequisite) - Functional Examples" href="../../examples/yui/index.html">YUI (Global Prerequisite)</a></li><li class="item"><a title="Event - Functional Examples" href="../../examples/event/index.html">Event</a></li><li class="item"><a title="Node - Functional Examples" href="../../examples/node/index.html">Node</a></li><li class="sect">YUI 3 Component Infrastructure - Examples</li><li class="item"><a title="Attribute - Functional Examples" href="../../examples/attribute/index.html">Attribute</a></li><li class="item"><a title="Base - Functional Examples" href="../../examples/base/index.html">Base</a></li><li class="sect">YUI 3 Utilities - Examples</li><li class="item"><a title="Animation - Functional Examples" href="../../examples/anim/index.html">Animation</a></li><li class="item"><a title="Cookie - Functional Examples" href="../../examples/cookie/index.html">Cookie</a></li><li class="item"><a title="Drag &amp; Drop - Functional Examples" href="../../examples/dd/index.html">Drag &amp; Drop</a></li><li class="item"><a title="Get - Functional Examples" href="../../examples/get/index.html">Get</a></li><li class="selected "><a title="IO - Functional Examples" href="../../examples/io/index.html">IO</a></li><li class="item"><a title="JSON (JavaScript Object Notation) - Functional Examples" href="../../examples/json/index.html">JSON</a></li><li class="item"><a title="Queue - Functional Examples" href="../../examples/queue/index.html">Queue</a></li><li class="sect">YUI 3 CSS - Examples</li><li class="item"><a title="YUI CSS Reset - Functional Examples" href="../../examples/cssreset/index.html">CSS Reset</a></li><li class="item"><a title="YUI Fonts - Functional Examples" href="../../examples/cssfonts/index.html">CSS Fonts</a></li><li class="item"><a title="YUI Grids - Functional Examples" href="../../examples/cssgrids/index.html">CSS Grids</a></li><li class="item"><a title="YUI Base - Functional Examples" href="../../examples/cssbase/index.html">CSS Base</a></li><li class="sect">The YUI Community</li><li class="item"><a title="The Yahoo! User Interface Blog" href="http://yuiblog.com">YUI Blog (external)</a></li><li class="item"><a title="The Yahoo! Group YDN-JavaScript hosts the YUI community forum" href="http://tech.groups.yahoo.com/group/ydn-javascript/">YUI Forum (external)</a></li><li class="item"><a title="The Yahoo! Group yui3 is dedicated to the 3.x branch of the Yahoo! User Interface (YUI) Library." href="http://tech.groups.yahoo.com/group/yui3/">YUI 3 Forum (external)</a></li><li class="item"><a title="YUI is used by Yahoo! and by hundreds of other sites, including many you know and love." href="/yui/poweredby/">YUI Sightings (external)</a></li><li class="item"><a title="Videos and podcasts from the YUI Team and from the Yahoo! frontend engineering community." href="http://developer.yahoo.com/yui/theater/">YUI Theater (external)</a></li><li class="sect">YUI Articles on the YUI Website</li><li class="item"><a title="Answers to Frequently Asked Questions about the YUI Library" href="http://developer.yahoo.com/yui/articles/faq/">YUI FAQ (external)</a></li><li class="item"><a title="Yahoo!'s philosophy of Graded Browser Support" href="http://developer.yahoo.com/yui/articles/gbs/">Graded Browser Support (external)</a></li><li class="item"><a title="Reporting Bugs and Making Feature Requests for YUI Components" href="http://developer.yahoo.com/yui/articles/reportingbugs/">Bug Reports/Feature Requests (external)</a></li><li class="item"><a title="Serve YUI source files from Yahoo! -- free, fast, and simple" href="http://developer.yahoo.com/yui/3/articles/hosting/">Serving YUI Files from Yahoo! (external)</a></li></ul>
347</div>
348</div>
349        </div><!--closes bd-->
350
351        <div id="ft">
352        <p class="first">Copyright &copy; 2008 Yahoo! Inc. All rights reserved.</p>
353        <p><a href="http://privacy.yahoo.com/privacy/us/devel/index.html">Privacy Policy</a> -
354            <a href="http://docs.yahoo.com/info/terms/">Terms of Service</a> -
355            <a href="http://docs.yahoo.com/info/copyright/copyright.html">Copyright Policy</a> -
356            <a href="http://careers.yahoo.com/">Job Openings</a></p>
357        </div>
358</div>
359<script src="../../assets/dpSyntaxHighlighter.js"></script>
360<script language="javascript"> 
361dp.SyntaxHighlighter.HighlightAll('code'); 
362</script>
363</body>
364</html>
365<!-- delightfuture.corp.yahoo.com uncompressed/chunked Wed Aug 13 16:45:32 PDT 2008 -->
Note: See TracBrowser for help on using the repository browser.