How to check for error from the server and show message

How to check for error from the server and show message

LeronLeron Posts: 2Questions: 1Answers: 0

I'm trying to implement a very lightweight wrapper for DataTable which will handle mostly my custom filters. I do that like this :

(function ($) {

$.fn.MyExtension = function () {

var options;

$.ajax({
        url: ..//Get the init properties from a XML file
        success: function (data) {
            options = data;
         ....

//Create the dataTable
var oTable = $(this.selector).dataTable(options);


 What I do now is right before creating the dataTable instance to add this code :

        options.fnServerData = function (sSource, aoData, fnCallback) {
                $.getJSON(sSource, aoData, function (json)
                {
                    console.log(json);
                    if (json.aaData[0] != "Error") {
                        alert("error");
                        //location.reload(true);
                    }
                    fnCallback(json)
                });
         }

and then pass options to dataTable(options);

I still have problems dealing with dataTables so my questions are two. Is this the best way to handle errors from the server in my case, and also - I have a lot of event handlers which I use to send data to the server like so :

        oSettings = oTable.fnSettings();
        oSettings.aoServerParams.push({
            "sName": "user",
            "fn": function (aoData) {
                aoData.push({
                    "name": "SomeName",
                    "value": SomeValue
                });
            }   
        })
        oSettings.sAjaxSource = "/....";
        oTable.fnDraw();

I think that if I'm able to handle the error here, it would be better, since I'll have more information where the things went wrong but I don't know if it's possible.

Thanks
Leron

This discussion has been closed.