Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A shorthand method to posting JSON data using jQuery
(function($) {
$.postJSON = function(url, data, success, dataType) {
if (typeof data != 'string') {
data = JSON.stringify(data);
url : url,
type: "post",
data: data,
dataType: dataType || "json",
contentType: "application/json",
success: success

This comment has been minimized.

Copy link
Owner Author

@padcom padcom commented Jan 3, 2012

A shorthand version of the function that instead of doing a form post does a JSON post with the proper content-type. See for more information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment