Is it possible to delay the execution of a click on an anchor href in a Backbone view until an ajax call has been completed?
I am looking for the following functionality:
- User clicks an href;
- Click triggers an ajax call;
- If the ajax call is successful, then the href should be executed;
I attempted a test by adding a method to a Backbone view linked to an anchor:
clickNext: function(e){
setTimeout(function(){
console.log("test");
}, 5000);
Unfortunately, the href is being executed before the timeout finishes.
The necessity for this functionality arises from my desire to create a wizard where each page has a separate URL. I need to perform checks using local storage on each pageload and save data persistently using Ajax on every "Next" click.