Double ajax call when reloading datatable

Double ajax call when reloading datatable

nielvromnielvrom Posts: 2Questions: 0Answers: 0
edited November 2013 in General
I have a datatable intialised like this:

[code]
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;
});
};
var myDataTable = $('#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();
}
});
[/code]

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

[code]
$('.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;

myDataTable.fnReloadAjax("/results/load-results?" + getParams).fnDraw();
});
[/code]

But the data stays the same ... Here you see my ajax calls: http://nl.tinypic.com/view.php?pic=wbwggz&s=5#.Uoqb7WRaZ8I

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/ (doesn't work, but you see my code ..)

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You are using server-side processing, so every draw makes an Ajax request. So the reason it is doing to requests is that you call fnReloadAjax (first request) and then fnDraw (second request). Just call fnReloadAjax .

    Allan
  • nielvromnielvrom Posts: 2Questions: 0Answers: 0
    Ok, I deleted the ".fnDraw()" but it's still the same ..
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Can you link me to the page please? That looks like it should work.

    Allan
This discussion has been closed.