Skip to content

Instantly share code, notes, and snippets.

@nozzlegear
Last active February 8, 2018 22:44
Show Gist options
  • Save nozzlegear/9e45a63675178b5d6261 to your computer and use it in GitHub Desktop.
Save nozzlegear/9e45a63675178b5d6261 to your computer and use it in GitHub Desktop.
Extending jQuery to send json in a post
jQuery.postJSON = function (url, data, success, dataType) {
if (dataType === void 0) { dataType = "json"; }
if (typeof (data) === "object") { data = JSON.stringify(data);}
var ajax = {
url: url,
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: dataType,
data: data,
success: success
};
return jQuery.ajax(ajax);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment