3

Working with Datatables. Trying to get work function (which currently works ONLY with GET) with POST.

Based on this discussion I modified this function and got something like below. Now getting error message:

json.aaData is undefined @ line 99

Whole code is here

        jQuery.post( sSource, aoData, function (data) { 
            /* Callback processing */
            oCache.lastJson = jQuery.extend(true, {}, data);

            if ( oCache.iCacheLower != oCache.iDisplayStart )
            {
                data.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower );
            }
            data.aaData.splice( oCache.iDisplayLength, data.aaData.length );

            fnCallback(data)
        },"json" );
    }
    else
    {
        json = jQuery.extend(true, {}, oCache.lastJson);
        json.sEcho = sEcho; /* Update the echo for each response */
        json.aaData.splice( 0, iRequestStart-oCache.iCacheLower ); // <- this line
        json.aaData.splice( iRequestLength, json.aaData.length );
        fnCallback(json);
        return;
    }
}

What am I missing? Any suggestion?

6
  • Try providing more details, or localising the problem, so more people will try to answer. Commented May 13, 2012 at 19:15
  • @LukaRamishvili I really don't know, what's problem. I provided info, that I know Commented May 13, 2012 at 19:16
  • @LukaRamishvili But, I have suggestion that, It's something related with variable names. Commented May 13, 2012 at 19:16
  • 2
    Did you know that you only have to write jQuery in its long form once? By wrapping your code in (function($) { .... })(jQuery);, you can use $ no matter if noConflict has been used or not. Commented May 13, 2012 at 19:19
  • @ThiefMaster It's not my code. Please take a look at links that I provided Commented May 13, 2012 at 19:21

2 Answers 2

1

It's jQuery.post( sSource, aoData, function (data) {. You have aoData, but in the code you reference aaData. It may be a typo.

Sign up to request clarification or add additional context in comments.

4 Comments

Now, json.aoData is undefined @ line 99
Guys, I found error: PHP returns value with 1-2 second delay jQuery.post doesn't wait for response, I think. How do you think, is it possible to fix that problem?
$.ajax({...type: "POST", response:function(data){/*do something with data*/}...});
I resolved this problem already. Can you pls take a look at this problem? stackoverflow.com/questions/10612904/…
0

So the full code sample you provided, couldn't possibly be the full code, because it's only 75 lines long, and you are getting an error that says you have an undefined property on line 99.

However, you did say that this line:

json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );

is giving you the undefined error. What's happening is you are trying to access the splice function of a property aaData which does not exist on your json object for some reason.

So if you open up your JavaScript console and type json.aaData, you will see that it returns undefined. So whatever is supposed to set the aaData property of the json variable is not doing so. I hope this helps you track down your error.

4 Comments

Ok so based on your screen cast it looks like the JSON object you're getting from question.php is returning with a property called aaData. I would suggest clicking on the tab "Script" to the right of Console. And where it says "Inline" click that and look for the file that contains your script. Next scroll down to the line number that the aaData property is being access and click the green line number. You should see a little red dot appear next to the number. That's setting a breakpoint. Now look on the right for your json variable and see if aaData is set.
Is undefined. Please take a look at original version of script datatables.net/release-datatables/examples/server_side/… lines 80-91 I changed to Post. I think something goes wrong because of this
Guys, I found error: PHP returns value with 1-2 second delay jQuery.post doesn't wait for response, I think. How do you think, is it possible to fix that problem?
Hey, so you could setup an interval function to keep asking for it until it either gets it or timesout: var secondsCounted = 0; var interval = setInterval(function(){ if ( json.aaData ) { //do what you need to do and clear interval //...do stuff clearInterval(interval); } else { if (secondsCounted == 10) { console.log('json.aaData not found due to timeout'); clearInterval(interval); return; } secondsCounted++; } },1000);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.