So I have a Spring Boot API project using Jquery SmartWizard. The first Step of 4 contains a simple form. For the sake of testing, am using with one field (ID: first-name).
On clicking of the Next
button of the Wizard, the jquery method should execute, form details posted to the database and then go to the Next Step
of the Wizard(i.e. 2).
$( document ).ready(function() {
$('#wizard').smartWizard({
onLeaveStep: function() {
ajaxPost();
}
});
$('.buttonNext').addClass('btn btn-success');
$('.buttonPrevious').addClass('btn btn-primary');
$('.buttonFinish').addClass('btn btn-default');
function ajaxPost(){
var formData = {
name : $("#first-name").val()
//lastname : $("#lastname").val()
};
// DO POST
$.ajax({
type : "POST",
contentType : "application/json",
url : "http://localhost:8080/api/uc/create",
data : JSON.stringify(formData),
dataType : 'json',
success : function(result) {
console.log(result)
},
error : function(e) {
alert("Error!");
console.log("ERROR: ", e)
}
});
//$('#wizard').smartWizard('goForward');
// Reset FormData after Posting
//resetData();
}
function resetData(){
$("#first-name").val("");
//$("#lastname").val("");
}
});
The ajaxPost()
works but the Wizard doesnt move to the next step. If I uncomment this line //$('#wizard').smartWizard('goForward');
The ajaxPost() function replicates alot of data in the database then.
How do I get the Wizard to move to Step 2 after doing the form submit via the ajax functionality by clicking on the next button.