Skip to content

Instantly share code, notes, and snippets.

@buzzedword buzzedword/ajax-events.js
Last active Dec 13, 2015

Embed
What would you like to do?
$("#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
You can’t perform that action at this time.