I am trying to learn promises using jQuery (current version 3.2.1.)
I want to run the get request only after the post request is successful, but my current code does not work. Submitting the data works fine but the get request does not run. I am not sure how I can chain this two actions?
$('#newPoiForm').submit(function (e) { // handle the submit event
e.preventDefault();
let formData = $(this).serialize();
console.log(formData);
$.post({
type: 'POST',
url: '/api/pois/',
data: formData
}).done(function(){
console.log('new asset submitted')
return $.get({url: '/api/pois/last'})
}).then(function (data) {
// do stuff
})