Problem with drag and drop

0

Good, I really do not know how to ask the question, what happens to me is that when I try to upload a file with the tool, my browser has a memory crash, really do not explain it. Here is the function in Java Script.

            $(function(){
      var dragEntrada = document.getElementById('dragEntrada');

//tengo problemas cuando coloco esta función      
var upload = function(files){
        var formData = new FormData(),
        xhr = new XMLHttpRequest(),
        x;
        for (var x = 0; x < files.length; x+1) {
          formData.append('file[]', files[x]);
        }
        xhr.onload = function(){
          var data = this.responseText;
          console.log(data);
        }

        xhr.open('post', 'upload.php');
        xhr.send(formData);
      }
   // 
      dragEntrada.ondrop = function(e){
        e.preventDefault();
        this.className = 'dragEntrada';
        upload(e.dataTransfer.files);
      }

      dragEntrada.ondragover = function(){
        this.className = 'dragEntrada dragover';
        return false;
      }

      dragEntrada.ondragleave = function(){
        this.className = 'dragEntrada';
        return false;
      }

    }());

If you need another part of the code I will be waiting to place it, thank you very much.

    
asked by Juan Romero 08.07.2017 в 05:44
source

1 answer

0

The problem is in:

 for (var x = 0; x < files.length; x+1)

This generates an infinite loop because the statement x+1 adds 1 to x but the result does not assign it to variable x so this variable always has value 0 and never comes out of the loop.

Change it to:

 for (var x = 0; x < files.length; x++)

var x=0;
x+1;
console.log('Valor después de x+1: ' + x);
x++;
console.log('Valor después de x++: ' + x);
    
answered by 08.07.2017 / 10:04
source