Fork me on GitHub Fork me on GitHub

post()


<%
var url = 'http://jaggeryjs.org/apidocs/resources/data.jag';
var result = post(url, 'Jaggery HTTP POST', {
    "User-Agent" : "Jaggery-XHR",
    "Country" : "LK"
}, 'json');
print(result.data);
%>

Overview

post() is a wrapper for XMLHTTPRequest's POST method. Using post() you can avoid the use of XHR and shorten the serverside POST requests. If the Content-Type header is not specified, application/x-www-form-urlencoded; charset=UTF-8 will be set automatically.

Asynchronous Invocation

post(url[, data][, headers][, type][, success(data, xhr)])

Synchronous Invocation

var res = post(url[, data][, headers][, type])
Returned result contains the data and the XMLHttpRequest instance. { data: {}, xhr: {} }


Parameters

Parameter Type Description
urlString
var url = 'http://jaggeryjs.org/apidocs/resources/data.jag';
The URL which HTTP POST is performed
dataObject|String
var param = {param1: "value1", param2:"value2"}
Request parameters
headersObject
var cookie= {'name':'test','value':'Cookie testing'};
response.addCookie(cookie)

Adds the specified cookie to the response.

typeString
var type = "json"
The type, which the response is expected. Allowed types are json, xml or text. Returned response will be serialized either to an object, E4X XML or String depending on the value passed. text is the default value.
success(data:Object,
xhr:Object)
functionOn success callback. data will be passed according to the above mentioned type parameter passed during the invocation.

Return values

Value Type Description
dataObjectContains the return data of the HTTP POST request
xhrObjectContains an instance of XMLHTTPRequest