Skip to content Skip to sidebar Skip to footer

Javascript Exceed Timeout

I use jquery to develop mobile application, here is my code below the problem that when I add 5 or 6 line to the page contained all goes well. but if I add multiple line displays e

Solution 1:

Hard to know, how big is the results.row ? But you should start caching your jQuery objects and try to minimize your DOM-insertions

The followings is untested but it will point you in the right direction:

function succes_recu_list_rubrique(tx, results)   //apés avoire remplir sqlite
{
    console.log('ENTRééééééééééééééé---')

    var htmlToAppend ="";
    var$lbtn= $('#lbtn');

    htmlToAppend +="<legend>Selectionner un Rubrique</legend><br>";

    for( var i=0; i<results.rows.length; i++  )            //Remplir tableau liste des identifiants étapes
    { 
        htmlToAppend +="<input name='opt1' checked type='radio' value="+results.rows.item(i).IdRubrique+" id="+results.rows.item(i).IdRubrique+" />";
        htmlToAppend +="<label for='+results.rows.item(i).IdRubrique+'>'+results.rows.item(i).LibelleRubrique+'</label>";
    }
    $lbtn.append(htmlToAppend);

    $lbtn.append('<a href="#page_dialog2"class="offer2"      data-rel="dialog"    data-role="button">Consulter</a>').trigger('create');
    $lbtn.append('<a href="#'+id_grp_rub+'"   data-role="button"             data-rel="back" data-theme="c">Cancel</a> ').trigger('create');

}

Solution 2:

@soderslatt is headed in the right directions. See http://www.learningjquery.com/2009/03/43439-reasons-to-use-append-correctly for how to append to an element that is NOT attached to the DOM (and avoid repaint & reflow) and then append it to the DOM and pay the penalty only once

Solution 3:

The below solution will solve your issue. The trick is to use the setTimeout function with a very small number of 1 millisecond to wait before executing the code. Using the mentioned way will allow you to unlock the thread and avoid the exceed timeout error.

Sample Example:

functionsucces_recu_list_rubrique(tx, results) {

    var i = 0;

    functionappendOperation() {
        $('#lbtn').append(
            [
                "<input name='opt1' checked type='radio' value=", results.rows.item(i).IdRubrique, " id=", results.rows.item(i).IdRubrique, " />",
                "<label for=", results.rows.item(i).IdRubrique, ">", results.rows.item(i).LibelleRubrique, "</label>"
            ].join("")
        );

        if (i++ < results.rows.length) {
            setTimeout(appendOperation, 1);
        } 
    }
    appendOperation();
}

Post a Comment for "Javascript Exceed Timeout"