Problem when using fnReloadAjax() together with sAjaxSource
Problem when using fnReloadAjax() together with sAjaxSource
Hi there,
I am a chinese developer who using DataTables recently.
The problem I met is that, when I set the table source to "sAjaxSource", then install fnReloadAjax plugin to refresh the data, it always make 2 ajax calls.
The code is something like this :
===============================================================================
[code]
var params = '?xxx=xxx';
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback )
{
// content copied from http://datatables.net/plug-ins/api
}
......
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../examples_support/server_processing.php/" + params
} );
} );
......
oTable.fnReloadAjax("../examples_support/server_processing.php/" + params);
[/code]
===============================================================================
Then I go to firebug, and every time, it make 2 ajax calls.
"params" is dinamic which from user.
Did any of you had ever met this problem ?
I am a chinese developer who using DataTables recently.
The problem I met is that, when I set the table source to "sAjaxSource", then install fnReloadAjax plugin to refresh the data, it always make 2 ajax calls.
The code is something like this :
===============================================================================
[code]
var params = '?xxx=xxx';
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback )
{
// content copied from http://datatables.net/plug-ins/api
}
......
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../examples_support/server_processing.php/" + params
} );
} );
......
oTable.fnReloadAjax("../examples_support/server_processing.php/" + params);
[/code]
===============================================================================
Then I go to firebug, and every time, it make 2 ajax calls.
"params" is dinamic which from user.
Did any of you had ever met this problem ?
This discussion has been closed.
Replies
If you read the text which says what fnReloadAjax does it says: "Note: To reload data when using server-side processing, just use the built-in API function fnDraw rather than this plug-in."
:-)
Regards,
Allan
But another problem is I want to make the "params" dinamic, depending on some other input fields (for example).
And if I use fnDraw, it just redraw the table, but never fresh the data by "params" provided.
[code]
$.fn.dataTableExt.oApi.myReload= function ( oSettings, sNewSource )
{
if ( typeof sNewSource != 'undefined' ) {
oSettings.sAjaxSource = sNewSource;
}
this.fnDraw( this );
}
[/code]
oTable.myReload("../examples_support/server_processing.php/" + params);
Can you give me your advice on whether it's right ? Or is there an easier way to do it ?
Thank you.
I suspect that is not quite right either. Have a look at this example for how to set your own custom variables to send to the server: http://datatables.net/examples/server_side/custom_vars.html
Regards,
Allan
Yes, this function is really works well.
But the problem of double ajax call still exists ... I aim at making every request to be only one ajax call ...
Allan
The example works so well now, and what's more, the fnCallBack is really what I am looking for so far.
I make the ajax call in once and then do all the things with callback funciton. That's really nice.
Here is my code :
[code]
oTable = $('.myTable').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "myAjaxGetData/",
"fnServerData": function ( sSource, aoData, myCallback ) {
aoData = myParamsCollection(aoData);
$.getJSON(sSource, aoData, function (json) {
myCallback(json);
});
},
});
[/code]
Then just call fnDraw to refresh at any time I want.
Thanks again for your patient !
Kim
thanks for the script, its working fine for me
Diane Sims
http://www.blenderreviewer.com/