"Unresponsive script"

Hi,I need some help please I am using jquery.ajax in querying data to my database,but I am having trouble my page get stuck or freeze and it shows “Unresponsive script” jquery.min.js ,what causes jquery script to unresponsive.?.

Thank you in advance.

Hi jemz,

Generally this means either your ajax requesting is attempting to pull far too much data back through or trying to push too much through, either way we would need to see what you’re doing to determine which of those it is.

The last I saw this error in my code I was trying to put too much in localStorage. (using too much memory)
I upped my browser’s limits but ultimately decided throwing more memory at it wasn’t the best soluition and used a database instead.

This is what I am doing, I am using MySQL,I inspect in firebug the size of respond data is 1.7mb


     $.ajax({
        type: 'post',
        data: 'process=' + 'findlocation ' + '&' + formdata,
        url: 'process/process.php',
        success: function (data) {
            //converting lat and lng to readable address
      }

process.php


 include_once 'myfunction.php';

     switch ($process){
      ...some case here
      .....
       ......

        case 'findlocation':

          //getting the post parameter

           $direction = direction(some parameters here);

          echo $direction;

         break;


  }


myfunction.php


   function direction(parameters here){

    SELECT latitude,longitude,DATE(dateTime) as 'vehicleDate', TIME(dateTime) as 'VehicleTime'  FROM  vehicle
                          WHERE `dateTime` 
                        BETWEEN CAST(CONCAT('$date1',' ','$startTimeFrom') AS DATETIME)
                           AND CAST(CONCAT('$date2',' ','$endStartTime') AS DATETIME)
                           AND (vehicle_id='000010')
             ORDER BY vehicleDate,VehicleTime ASC

    $results = array(
        'lat' => array(),
        'lng' => array(),
        'vehdate'=> array(),
        'vehtime'=> array(),

    );

     while($row=mysql_fetch_array($result,MYSQL_BOTH)){

        $results['lat'][] = $row['latitude'];
        $results['lng'][] = $row['longitude'];
        $results['vehdate'][] = $row['vehicleDate'];
        $results['vehtime'][]= $row['VehicleTime'];
       
    }

    return json_encode($results);
}

Hope this helps,

Thank you in advance.

Hi Mittineague,

can you help me please where I can see if my app using too much memory ?..sorry for this silly question but I am curious how to determine if my works is using too much memory.

Thank you in advance.

@chris.upjohn , Is there something wrong with my code ?

I had the problem a couple years ago so I don’t remember the details.

Basically I wrote a userscript that gathered information from pages and stored it to localStorage. At the time I would have never guessed how much data I would be working with or how fast it would add up.
It worked fine until the amount of information got too large (~2K if I recall correctly) and I started getting the “unresponsive script” message box popping up more and more often.
Looking in Firefox’s Error Console pointed to a memory problem.

I know how to go to about:config to increase the value, but I realized that just because I was pushing the limits of javascript beyond what would be normal and could compensate for it didn’t mean I should expect others to need to do the same. So I wrote an extension that uses SQLite instead.

Assuming PHP will have little problem dealing with a large multi-dimensional array, I’m guessing your probllem is either the array is too much for the javascript to deal with or is in the “converting” portion of your code.
success: function (data) { //converting lat and lng to readable address }

Hi Thank you for the reply,but the data is not yet returned in my success ,the browser will hang,…

Thank you in advance.

You have a jQuery “success”. Do you have a jQuery “fail” giving anything that might help solve the problem?

Hi Mittineague, You are right there is something wrong in my jquery inside my success,when I comment the function inside my success it works find the browser did not hang or freeze.

I think inserting the TR dynamically in jquery is the problem…I don’t know why this is cause for freezing.


function displayTable(){   

    var lno = 1;
   
    $('.mytablesearch').css('display', 'block');

      for (var n = 0, nlen = datacoord.lat.length; n < nlen; n++) {

             $('#mytable tr:last').after('<tr><td>' + lno + '</td><td>' + datacoord.thedate[n] + '</td><td>' + datacoord.thetime[n] + '</td><td>' + datacoord.lat[n] + '</td><td>' + datacoord.lng[n] + '</td></tr>');

             lno++;

      }
	  
}





Thank you in advance.

Sorry for the delay, I’ve been having a very hard time trying to get the forum to load properly. The code you posted above isn’t doing you any justice as you’re taking the long way to insert your data into the DOM, see the below which should vastly improve the performance of your code.

function displayTable() {
    var i   = 0,
        l   = datacoord.lat.length,
        $t  = $('#mytable');

    $('.mytablesearch').css('display', 'block');

    for (; i < l; i++) {
        $t.append('<tr>' +
            '<td>' + (i + 1) + '</td>' +
            '<td>' + datacoord.thedate[i] + '</td>' +
            '<td>' + datacoord.thetime[i] + '</td>' +
            '<td>' + datacoord.lat[i] + '</td>' +
            '<td>' + datacoord.lng[i] + '</td>' +
        '</tr>');
    }  
}

Hi chris.upjohn, thank you for the reply.

It improve performance than my code,but there is a problem when I tried to pull 25000 data , the browser gets “Not responding” about 6 secs and then it display to my table grid…I think I am in trouble if I will query 4 months of data.

Thank you in advance.

As I said earlier pushing too much data either way will cause issues, 25,000 results is far too many and will cause an unresponsive script as you’re asking the browser to insert too many elements which will cause it to either run out of memory or freeze permanently.

For the most ideal results it’s I recommend you paginate your results so you’re outputting 50-100 results instead.

Hi, Thank you for the reply…yes I think pagination is the best option thank you I will try apply pagination.

It’s working. :smile: