jquery datatables:加载实时进度条

时间:2016-01-28 18:23:47

标签: javascript jquery ajax datatables jqxhr

正常的ajax实时进度条像这样加载

$.ajax({
xhr: function() {
                var xhr = new window.XMLHttpRequest();
                xhr.upload.addEventListener("progress", function(e) {
                    var pro = (e.loaded / e.total) * 100;
                    $('.progress-bar-anim').css('width', pro + '%').attr('aria-valuenow', pro);
                }, false);
                return xhr;
            },
            type: "POST",
            dataType: 'json',
            url: "data.php",
            data: {"username": username, "password": password},
            success: function(msg) {
                if (msg.status == 'success') {
                    window.location = "dashboard.php"
                } else {
                    hide_progress();                 
                }
            }
        });

我想在收到服务器响应时在 jquery datatables 中加载实时进度条。我该怎么办呢?

1 个答案:

答案 0 :(得分:1)

在成功方法中创建表格:

function getData() {
    $.ajax({
      url : 'example.com',
      type: 'GET',
      success : handleData
    })
}

function handleData(data) {
    table = $('#table').DataTable( {
            "data": data,
            ....
}