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:
