Double ajax call when reloading datatable
Double ajax call when reloading datatable
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 ..)
[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 ..)
This discussion has been closed.
Replies
Allan
Allan