fnCallback is undefined

fnCallback is undefined

saifursaifur Posts: 20Questions: 0Answers: 0
edited May 2012 in General
I am using fnReloadAjax and data is retrieving properly from the server. But the table is not updating with new data. After debugging I found the value of fnCallback is undefined. My code is as below:

[code]
"bStandingRedraw" : false,
"bJQueryUI" : true,
"sPaginationType" : "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "<?php echo base_url(); ?>photos/generate_json_photolist/" + sValue,


"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}

[/code]

And I am calling fnReloadAjax on a change event of a select list. which is also given below:

[code]

$('#albumid').change(function() {

//sValue = $('#albumid').val();
//alert(sValue);
//oTable.fnClearTable();
//oTable.fnClearTable();
oTable.fnReloadAjax("<?php echo base_url(); ?>photos/generate_json_photolist/" + $('#albumid').val() );

});
[/code]

My fnReloadAjax function code is

[code]
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback)
{
console.log("here");
if ( typeof sNewSource != 'undefined' )
{
oSettings.sAjaxSource = sNewSource;
}
console.log(oSettings.sAjaxSource);
this.oApi._fnProcessingDisplay( oSettings, true );
var that = this;

oSettings.fnServerData( oSettings.sAjaxSource, null, function(json) {
/* Clear the old information from the table */
that.oApi._fnClearTable( oSettings );
//alert(json.aaData.length);
/* Got the data - add it to the table */
for ( var i=0 ; i

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    have you tried replacing fnCallback with a valid function (even void()) ?
  • saifursaifur Posts: 20Questions: 0Answers: 0
    I am not sure how to do that. Can you give me an example?
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    No it wouldn't be because fnCallback is undefined - the if conditional explicitly checks that it is a function before running it, and since you aren't passing one in, it is undefined and thus doesn't run. So not that.

    Probably the best way for us to be able to offer any help is for you to post a link to your page so we can see what is happening.

    Allan
  • saifursaifur Posts: 20Questions: 0Answers: 0
    Hi Allan,

    You have checked this earlier. Still facing the issue. Here is the link.

    URL:
    http://www.saifur.com/victor/admin
    It will ask for user name and password, use the following credentials.
    user: saifur
    pass: mankind

    then there you will find a menu, go to photo->add new
    That is the page I am asking help for.

    Thanks in advance.
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    Ah yes - I remember now :-). And as far as I can see, the problem is still the same as before - I upload a photo by licking the 'Upload' button and then the page refreshes without showing my photo (although there is a new row added - which I presume is where it should be).

    Given that there is a page refresh, what is fnReloadAjax being used for? Surely since you are reloading the page it will just get the latest data anyway.

    Allan
  • saifursaifur Posts: 20Questions: 0Answers: 0
    Don't upload, just try changing the select box. I need fnReloadAjax for that only.
  • saifursaifur Posts: 20Questions: 0Answers: 0
    Once that works, I won't use the page refresh anymore. I will upload using ajax call.
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    Oh I see - you've got server-side processing enabled, but your script is always returning sEcho=1 - thus DataTables is throwing it away - from the documentation ( http://datatables.net/usage/server-side ):

    > An unaltered copy of sEcho sent from the client side. This parameter will change with each draw (it is basically a draw count) - so it is important that this is implemented. Note that it strongly recommended for security reasons that you 'cast' this parameter to an integer in order to prevent Cross Site Scripting (XSS) attacks.

    Do you really need server-side processing in this table? You should only need it for tables which are many many thousands of records.

    Allan
  • saifursaifur Posts: 20Questions: 0Answers: 0
    Nope, I really don't need server side processing. What should I do then? Would be appreciated if you can point me exactly where to make the changes and what.
  • saifursaifur Posts: 20Questions: 0Answers: 0
    Hey Allan, thanks a lot. It simply works when I made "bServerSide": to false.
This discussion has been closed.