Skip to content

Instantly share code, notes, and snippets.

@mcunha98
Created September 29, 2019 18:40
Show Gist options
  • Select an option

  • Save mcunha98/926021db2c12017c603ea2f31045de24 to your computer and use it in GitHub Desktop.

Select an option

Save mcunha98/926021db2c12017c603ea2f31045de24 to your computer and use it in GitHub Desktop.
(function ($) {
$.postJSON = function (url, data) {
var o = {
url: url,
type: "POST",
dataType: "json",
contentType: 'application/json; charset=utf-8'
};
if (data !== undefined) {
o.data = JSON.stringify(data);
}
return $.ajax(o);
};
} (jQuery));
//estrutura de exemplo:
$.postJSON('/post/url', {param1: "hello", param2: "world"})
.complete(function () {
// Optional - fires when the operation completes, regardless of status
})
.success(function () {
// Optional - fires when operation completes successfully
})
.error(function () {
// Optional - fires when operation completes with error
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment