I'll tell you, I've been developing a PHP platform with codeigniter 3.0, I'm connected to a local SQL Server database, in which I have a job called Automatic. This job is executed using the function of the model "execute_job":
CONTROLLER
public function ejecutar() // Enfocado a UCF - Consolidar BBDD
{
$this->load->model('modelo');
$this->modelo->ejecutar_job();
}
MODEL
function ejecutar_job()
{
try
{
$query = $this->db->simple_query("EXEC msdb.dbo.sp_start_job 'Automatico';");
return 1;
}
catch(Exception $e)
{
echo $e;
return 0;
}
}
So far so good, but since it is a job that takes more less 2 min. I need a way for the platform to distinguish when it has finished its process. For this I thought about AJAX, implementing the following code:
AJAX in VISTA
<script type="text/javascript">
$("form").submit(function(event)
{
var url="<?php echo base_url("index.php/welcome/ejecutar");?>";
event.preventDefault();
$.ajax({
type: 'POST',
url: url,
beforeSend: function(){
$('#cargando').html("<img src='<?php echo base_url('imagenes/cargando.gif');?>'>");
},
})
.done(function(data) {
alert('Envío Satisfactorio!');
location.href = "<?php echo base_url('index.php/welcome/descargar_consolidado');?>";
})
})
</script>
This code should put an image.gif while the action is running and when it is finished, it would jump to the ".done" function redirecting to the file download page.
The problem is: the execution of the job if it is done, and it also redirects to the download page, but I can not keep the image "loading" all the execution time. Rather just try to drive the AJAX jumps to '.done' without having finished the execution time, which causes the download document is not ready.
It may be a very simple error or problem, but I can not solve it. If they give me help, it would be great ...
Greetings!