重装数据表时,双Ajax调用 [英] Double ajax call when reloading datatable

查看:132
本文介绍了重装数据表时,双Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表intialised是这样的:

I have a datatable intialised like this:

var _initTable = function() {
    $('#datatablesresults tr').not(':first').on('click', function() {
        var dateandtime = $(this).find(':nth-child(3)').text();
        window.location.href = '/results/detail/dateandtime/' + dateandtime;
    });
};

$('#datatablesresults').dataTable({
    bProcessing  : true,
    sProcessing  : true,
    bServerSide  : true,
    sAjaxSource  : '/results/load-results',
    fnServerParams: function ( aoData ) {
        aoData.push( {"name": "quizid", "value": quizid },{ "name": "questionid", "value": questionid } );
    },
    aoColumnDefs : [{'bSortable' : false, 'aTargets' : ['no-sort']}], // make the actions column unsortable
    sPaginationType : 'full_numbers',
    fnDrawCallback  : function(oSettings) {
        _initTable();
    }
});

当我点击一个按钮,我想重新加载在表中的数据(使一个AJAX调用)

When I click on a button I want to reload the data in the table (make an ajax call)

$('.carousel-control.right').click(function() {
    var currentquestion = $('#myCarousel .active').index('#myCarousel .item') + 1;
    var question = currentquestion + 1;

    var quizid = <?= json_encode($quizid); ?>;

    var activediv = $('.item').filter('.active');
    var questionid = activediv.index() + 2;

    var questionclass = ".question" + questionid;

    var questionid = $(questionclass).attr("id");

    var getParams = "quizid=" + quizid +"&questionid=" + questionid;

    $("#datatablesresults").dataTable().fnReloadAjax("/results/load-results?" + getParams);
});

但数据保持不变......在这里,你看我的Ajax调用:

But the data stays the same ... Here you see my ajax calls:

在我的网页加载第一是。第二是我的ajax刷新,这是重发不同,那么其他的数据。但是当你看到有另外一个AJAX调用重写数据...:/

The first is when my page is loaded. The second is my ajax refresh, the data that's resend is different then the other. But then you see there's another ajax call that overwrites the data ... :/

有谁知道我在做什么错了?

Does anyone knows what I'm doing wrong?

编辑:我做了一个的jsfiddle: http://jsfiddle.net/8TwS7/

I've made a jsfiddle: http://jsfiddle.net/8TwS7/

推荐答案

在调用此行

$("#datatablesresults").dataTable().fnReloadAjax("/results/load-results?" + getParams);

您再次重新初始化数据表

you are re-initializing the datatables again

将您的数据表()在doc准备在一个变量中,然后调用fnDraw()重绘表...就像我在您的其他问题回答<一href="http://stackoverflow.com/questions/20003316/reload-datatable-data-with-ajax-call-on-click">Reload在点击与Ajax调用数据表中的数据。

place your datatables() in the doc ready in a variable, then call fnDraw() to redraw the table...like i answered in your other question Reload datatable data with ajax call on click

如果您需要更多的帮助后你的整个的js code,我会告诉你。

if you need more help post your entire js code and i'll show you

这篇关于重装数据表时,双Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆