How to identify when someone is uploading to the page?

Asked

Viewed 90 times

4

I need to refresh the page every 5 minutes, but I have a form for sending 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);
  • How are you updating the page? With meta or javascript?

  • edited the question, I’m using Javascript

2 answers

7


If the upload is being carried out via POST of the form, the page makes refresh to send the data.

If the upload is being carried out via Ajax, 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 must adapt the same to your reality.

2

Assuming you are aware of the low reliability of a condition made exclusively in Javascript, you can run something in the upload field’s onChange() Event:

With jQuery

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

Without it, however inline:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.