YUI 3.x Home -

YUI Library Examples: IO: POST Transaction

Note: This is YUI 3.x. Looking for YUI 2.x?

IO: POST Transaction

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.

  • IO POST response data will appear here.

Using IO to Post Data and Receive the Server Response via HTTP POST

Create a YUI Instance

Create a YUI instance, using IO, for this example:

Assemble a Configuration Object for a POST Transaction

The IO configuration object support allows you to designate the transaction method (POST in this case) and other information, including data that should be sent as the POST body:

Create Handlers to Process Successful and Unsuccessful Transactions

Our handlers for the events that fire on successful and unsuccessful responses will write out information about the transaction to the innerHTML of an element on the page:

Initiate the POST Transaction

The 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 requestButton; we wire that button to the IO request with the following code:

Full Code

The full JavaScript code for this example follows:

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings