开发者

Loading datatable(jquery) with ajax after page load AND/OR let the images load first

开发者 https://www.devze.com 2023-03-07 23:58 出处:网络
Hey guys.I have an Ajax-loaded data table.The load goes fine but the one thing I notice is the text on the page is loaded but the header image and footer image is loaded after the Ajax call.This looks

Hey guys. I have an Ajax-loaded data table. The load goes fine but the one thing I notice is the text on the page is loaded but the header image and footer image is loaded after the Ajax call. This looks a little weird on the page. I'm wondering if there is a way to get around this. I know about the setTimeOut method in jQuery but baffled on how to use that with data tables.

$(document).ready(function() {

    var selected;
    var selectedOutput;
    var template;
    var submitButton;

    var insertedTable =  $('#pkgLineTable').dataTable({
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        "bPaginate": true,
        "bLengthChange": true,
        "bFilter": true,
        "bSort": false,
        "bInfo": true,
        "bAutoWidth": false,
        "bProcessing": true,
        "bServerSide": false,
        "sAjaxSource": '@{Overview.getPkgLineList()}',
        "fnServerData": fnServerObjectToArray(['shortname', 'description'])开发者_JAVA百科             
    });
});

  fnServerObjectToArray = function (aElements) {     

    return function (sSource, aaData, fnCallback) {
        $.ajax({
            "dataType": 'json',
            "type": "GET",
            "url": sSource,
            "data": aaData,
            "success": function (json) {
                var a = [];
                $.each(json, function(index, item) {     
                    var inner = [];
                    for (var i = 0, iLen = aElements.length; i < iLen; i++) {
                        inner.push(item[aElements[i]]);
                    }
                    a.push(inner);
                });
                json.aaData = a;
                fnCallback(json);
            }
        });
    }
}


If you want to load the ajax after the images have finished, use load instead of .ready:

$(window).load(function() {

    var selected;
    var selectedOutput;
    var template;
    var submitButton;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号