Below I have script js
and form.
$(document).on('submit','#form_create_user',function(e){
e.preventDefault();
var fd = new FormData(this);
var obj = $(this);
fd.append('course_id', "<?php echo $this->uri->segment(4); ?>");
obj.find('input[type="submit"]').val("Creating...")
$.ajax({
url: $(this).attr("action"),
data: fd,
cache: false,
processData: false,
contentType: false,
type: 'POST',
success: function (dataofconfirm) {
// do something with the result
// obj.find('input[type="submit"]').val("Confirm")
}
});
$.ajax({
url: "<?php echo site_url('home/saveValues/'); ?>",
data: fd,
cache: false,
processData: false,
contentType: false,
type: 'POST',
success: function (dataofconfirm) {
// do something with the result
toastr.success("Success created user.");
obj.find('input[type="submit"]').val("Confirm")
}
});
})
<form action="?" method="post" name="form_create_user" id="form_create_user">
<input name="username" type="text" id="username" value="test"><input type="submit" name="Submit" value="Confirm">
</form>
When I click on submit form then this script change text on button from “create” to “creating…” and display success action. But now this take about 1sec.
I need extand this script and I need:
display “creating…” for one minute and then return a success action.
note: the script run by form I need to set to run immediately, but only return success after a minute and reload the page.
Can anyone help me?