I find myself a bit puzzled here.
Currently, I'm developing a JavaScript form that sends values to a PHP page (submit.php
). If the PHP page returns a success message, I plan to redirect the user to another page (success.php
).
var url = 'submit.php';
var furl = 'success.php';
var formdata = new FormData();
formdata.append("name", 'John');
formdata.append('staffid',123);
formdata.append('csrf_test_name',csrf_token);
var ajax = new XMLHttpRequest();
ajax.addEventListener("load", function(event) {
uploadcomplete(event,furl);
}, false);
ajax.open("POST", url);
ajax.send(formdata);
function uploadcomplete(event,furl) {
var response = event.target.responseText.trim();
if(response=='Failed') {
alert('Failed');
} else {
alert('Success');
window.location.replace(furl);
}
}
function showLoader(){
document.getElementById('loader').style.display = 'block';
}
function hideLoader(){
document.getElementById('loader').style.display = 'none';
}
However, I want to display a loading icon while the form data is being processed and hide it when the process is complete. To accomplish this, I have created two functions - showLoader()
and hideLoader()
.
Now, my question is, where should I integrate these functions?