Skip to content

Instantly share code, notes, and snippets.

@buzzedword
Last active December 13, 2015 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buzzedword/4946859 to your computer and use it in GitHub Desktop.
Save buzzedword/4946859 to your computer and use it in GitHub Desktop.
$("#submit-btn").on('click', function(event) {
event.preventDefault();
var form, url, data, requests;
form = $("#form");
url = form.attr('action');
data = form.serializeArray();
requests = {
getJsonAction : 'http://url.com' // No query param here. jsonp mode sets it.
};
// The functions which handles success and failure
var responseHandler = {
success: function(data){
console.log('Response was successful.', data);
},
error: function(data){
console.log('Response issued an error.', data);
}
};
// Use raw AJAX for finer control over jqXHR object.
$.ajax({
dataType: "jsonp",
url: requests.getJsonAction,
type: 'POST'
}).done(responseHandler.success)
.fail(responseHandler.fail);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment