Last active
December 13, 2015 17:19
-
-
Save buzzedword/4946859 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#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