Skip to content

Instantly share code, notes, and snippets.

@skangmy
Created October 21, 2022 08:14
Show Gist options
  • Save skangmy/6c585d12ad776db0cdbb4eb63bf672be to your computer and use it in GitHub Desktop.
Save skangmy/6c585d12ad776db0cdbb4eb63bf672be to your computer and use it in GitHub Desktop.
jquery http post function
function post(url, data) {
return new Promise((resolve, reject) => {
$.ajax({
url,
dataType: 'json',
type: 'post',
contentType: 'application/json',
data: JSON.stringify(data),
processData: false,
success: function (response, textStatus, jQxhr) {
resolve(response);
},
error: function (jqXhr, textStatus, errorThrown) {
reject(errorThrown);
},
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment