Disable error reporting?

Disable error reporting?

andrew2311andrew2311 Posts: 11Questions: 0Answers: 0
edited February 2012 in General
I have noticed that in some cases datatables will pop up an alert ("Invalid JSON"). Is there any way to disable this?

Replies

  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    Yeah - return valid JSON :-).

    In all seriousness, you can have DataTables throw an error rather than 'alert'ing it by using:

    [code]
    $.fn.dataTableExt.sErrMode = 'throw';
    [/code]

    But really valid JSON would be the way to go, since the error is there for a reason :-)

    Allan
  • andrew2311andrew2311 Posts: 11Questions: 0Answers: 0
    Thanks allan

    I do use valid JSON it's just that sometimes the issue is out of my control - I have my datatables refreshing from the server and if the user undeploys the web app the datatables will get a 404 which obviously isn't valid JSON :-)
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    Heh - fair enough :-). The other option is to use fnServerData to override the built-in data get, which has the alert options in it with something of your own. But throwing an error should be fine.

    Allan
  • andrew2311andrew2311 Posts: 11Questions: 0Answers: 0
    So I've tried the proposed method and can't get it to work: http://live.datatables.net/oyinin/94/edit

    In Internet Explorer an alert is not shown but in Chrome (17) and Firefox (10) the alert is still shown. If you click that link above and then push 'render' you should see it.

    Any ideas?
  • andrew2311andrew2311 Posts: 11Questions: 0Answers: 0
    I could be wrong but looking at the code it seems I may have to override fnServerData after all?

    This code:
    [code] "error": function (xhr, error, thrown) {
    if ( error == "parsererror" ) {
    alert( "DataTables warning: JSON data from server could not be parsed. "+
    "This is caused by a JSON formatting error." );
    }
    }
    [/code]

    Does not call _fnLog, which is what checks sErrMode
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    Good point - it used to be that fnServerData didn't have access to the internal logging function, but it does now so I've just updated the error function to call that, and thus it will obey the sErrMode option.

    This is in the 1.9.1.dev nightly version (available on the downloads page) and will be included in the 1.9.1 release.

    Regards,
    Allan
  • andrew2311andrew2311 Posts: 11Questions: 0Answers: 0
    Great, thanks a lot :)
  • Fyb3roptikFyb3roptik Posts: 9Questions: 0Answers: 0
    Is there a reason alert is being used instead of console.log? It seems it would be better to use console.log on production systems
This discussion has been closed.