I have a form on an html page that is sent to a php file. My idea is that once the form is sent and until the data is loaded into the php, an animation is displayed on the screen.
The problem is that the animation is not showing.
The html file is as follows
<html>
<head>
<meta charset="UTF-8">
<title>load</title>
<script type="text/javascript" src="js/jquery.js"></script>
<style>
#cargando,#carga{
text-align: center;
}
</style>
</head>
<body>
<form id=create method=POST action=archivo.php>
<input type=text name=nombre>
<input type="submit" value="Create" />
</form>
<div id='cargando' style='display:none'>
<img src="load.gif" ><h3>Cargando página ...</h3>
</div>
<div id=cargado></div>
</body>
</html>
<script>
$(document).on("submit", "form", function(event)
{
event.preventDefault();
$('#cargando').show();
var url=$(this).attr("action");
$.ajax({
url: url,
type: 'POST',
dataType: "JSON",
data: new FormData(this),
processData: false,
contentType: false,
success: function (data, status)
{
$('#cargando').hide();
$('#cargado').html(data); //content loads here
},
error: function (xhr, desc, err)
{
console.log("error");
}
});
});
</script>
And file.php is:
<?php
sleep(3);
echo $_POST['nombre'];
?>