rstaib / jquery-bootgrid

Nice, sleek and intuitive. A grid control especially designed for bootstrap.
http://www.jquery-bootgrid.com
MIT License
972 stars 364 forks source link

Presenting users with server-side errors #360

Open bellwood opened 7 years ago

bellwood commented 7 years ago

Making a post to help out any one who is wanting to present their users with errors from the server-side.

My application is based off this tutorial/example:

http://phpflow.com/demo/bootgrid-php-mysql-serverside-demo/

In my backend, if I'm not returning success/true/1, I am returning a string containing the error.

I am then handling that via the ajax error handler with ajax call made at the bottom of the script:

        $.ajax({
            type: "POST",
            url: "ajax.php",
            data: data,
            dataType: "json",
            success: function(response){
                $('#'+action+'_model').modal('hide');
                $("#grid").bootgrid('reload');
            },
            error: function(jqXHR, textStatus, errorThrown) {
                $('#'+action+'_model').modal('hide');
                $('#errorMessages').html(jqXHR.responseText);
                $('.alert').removeClass('hidden');
            }
        });

HTH