0

I have a lot of files ( more than 120k ) and I want to read them in case to add their content to my database. I have processed with php to list the main directory content and send the result as json to my javascript. In my javascript I just showed the result first when I got the error :

Warning : Unresponsive script A script on this page may be busy, or it may have stopped responding...

I can choose between Continue or stop the script. Here is my code :

$(document).ready(function(){

    $.post("old.php", {aucunParam: 0}, function(data){
        for(var file in data["files"]){
            $("body").append(data["files"][file]+'<br>');
        }
    }, "json");

});

How can I process the files and have a real time look at the processing ?

Mehdi Benmoha
  • 3,694
  • 3
  • 23
  • 43
  • 1
    reduce the amount of data you have to process, or rewrite your code so you can process the data in smaller chunks, with timeout hooks to connect the chunks. – Marc B Jun 20 '14 at 18:43
  • 1
    Have a look at http://stackoverflow.com/questions/10344498/best-way-to-iterate-over-an-array-without-blocking-the-ui for an example of what Marc B mentions – glendaviesnz Jun 20 '14 at 22:03

1 Answers1

0

This is not php problem. This is jquery problem.

Try something like:

$(document).ready(function(){
    $.post("old.php", {aucunParam: 0}, function(data){
        $("body").append(data["files"].join('<br>'));
    }, "json");
});
M-A-X
  • 404
  • 7
  • 15