How to identify when someone is uploading on the page?

4

I need to refresh the page every 5 minutes, but I have a form for uploading files on the page and are usually large files.

Is there any way to identify when someone is uploading a file with Javascript?

Javascript code:

setTimeout('location.reload();', 5000);
    
asked by anonymous 16.10.2014 / 17:03

2 answers

7
If the upload is being performed via the POST form, the page refreshes to send the data.

If upload is being performed via Ajax , you can use a global variable to control upload status:

var variavelGlobalControloUpload;

function minhaFuncaoUpload() {

    // upload começou, dar a conhecer à variavel de controlo
    variavelGlobalControloUpload = 'a carregar';
}

function atualizaPagina () {

   // Verifica se não está a carregar
   if (variavelGlobalControloUpload != 'a carregar') {

     // codigo para atualizar a pagina aqui!
   }
}

Note: This is a concept, you should adapt the same to your reality.

    
16.10.2014 / 17:15
2

Assuming you are aware of the low reliability of a condition made exclusively in JavaScript, you can perform something on the onChange () Event of the upload field:

With jQuery

$('#inputfileID').change(function(){
    alert( 'Something...' );
})​

Without it, however inline :

<input type="file" name="whatever" onchange="alert( 'Something...' );" />
    
16.10.2014 / 17:12