本文介绍了重新加载datatable时,双重ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! var _initTable = function(){ $('# datatablesresults tr')。not(':first')。on('click',function(){ var dateandtime = $(this).find(':nth-​​child(3)') ); 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: ,value:questionid}); }, aoColumnDefs:[{'bSortable':false,'aTargets':['no-sort']}],// make the actions column unsortable sPaginationType:'full_numbers', fnDrawCallback:function(oSettings){ _initTable(); } }); 当我点击一个按钮时,我想重新加载表中的数据(做一个ajax调用) $('。carousel-control.right')点击(function(){ var currentquestion = $ ('#myCarousel .active')。index('#myCarousel .item')+ 1; var question = currentquestion + 1; var quizid =<?= json_encode quiz quiz quiz $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ var questionclass =.question+ questionid; var questionid = $(questionclass).attr(id); var getParams =quizid =+ quizid +& questionid =+ questionid; $(#datatablesresults)dataTable()。fnReloadAjax(/ results / load-results?+ getParams ); }); 但是数据保持不变...在这里你看到我的ajax调用: 第一个是当我的页面被加载第二个是我的ajax刷新,重发的数据与另一个不同。但是,然后你看到另外一个ajax调用覆盖数据...:/ 有没有人知道我在做错什么? 编辑:我做了一个jsfiddle: http://jsfiddle.net/8TwS7/ 解决方案当您拨打此行 $(#datatablesresults)。dataTable()。fnReloadAjax(/ results / load-results?+ getParams); 您将重新初始化数据表 将你的datatables()放在文档中准备好一个变量,然后调用fnDraw()重绘表...就像我在你的另一个问题中回答如果需要更多帮助,请重新加载带有ajax呼叫的数据表数据 发布您的整个js代码,我会告诉你 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(); }});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);});But the data stays the same ... Here you see my ajax calls: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?EDIT: I've made a jsfiddle: http://jsfiddle.net/8TwS7/ 解决方案 when you call this line$("#datatablesresults").dataTable().fnReloadAjax("/results/load-results?" + getParams);you are re-initializing the datatables againplace 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 clickif you need more help post your entire js code and i'll show you 这篇关于重新加载datatable时,双重ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-06 13:42