Server-Side update: JSON variables should be explicitly converted

Server-Side update: JSON variables should be explicitly converted

DarkMortalDarkMortal Posts: 3Questions: 0Answers: 0
edited August 2010 in Bug reports
This Bug is also applied to latest version 1.7.1
Using Server-Side Update with Ajax request.
In [code]_fnAjaxUpdateDraw[/code] you use assignment from JSON:
[code]
oSettings._iRecordsTotal = json.iTotalRecords;
oSettings._iRecordsDisplay = json.iTotalDisplayRecords;
[/code]
This makes [code]oSettings._iRecordsTotal[/code] and [code]oSettings._iRecordsDisplay[/code] to be String type because json provide variables' values as String.
This has side effect in Bug with incorrect [code]sInfo[/code] display, like
[code]Showing 1 to 0 of 0 entries[/code]
for empty sets. The reason is that you use [code]===[/code] operator in [code]_fnUpdateInfo[/code], like
[code]oSettings.fnRecordsDisplay() === 0[/code]

Replies

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    Why is the JSON returning a string rather than a number for these parameters? Having DataTables do a parseInt on the returned numbers is just extra operation which isn't really needed.

    Allan
  • DarkMortalDarkMortal Posts: 3Questions: 0Answers: 0
    Ok, then possibly it is a problem with variable values how they are passed using JSON.
    But I rather prefer this safe operation due to that fact that it throws errors if such variables were incorrectly passed as not integer.

    If you do not agree please close this thread. Thanks!
  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    I think it's a good sanity check to ensure what should be send back is being sent back (at a basic level). Loosely typed languages can be great, but also are sometimes a bit of a pain when things like this crop up.

    Funny thing is that I haven't seen this question in the forum before, and now in about 2 days, there have been four posts about it. Did this come from a tutorial or something? Or just random coincidence?

    Regards,
    Allan
This discussion has been closed.