This is a migrated thread and some comments may be shown as answers.

[Solved] OnError event does not trigger when ajax response data is not JSON

0 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Richard Guo
Top achievements
Rank 1
Richard Guo asked on 25 Mar 2010, 09:28 PM
Hi there,

I have a page which contains a grid control using custom binding. The page requires authorization. After the user's session timeout, if the user clicks the refresh button or changes pages, the returned ajax response will be the html of the Sign In page. That is because the controller tries to redirect the user to there. In this case, a javascript error will happen because the response data cannot be parsed.

I added the try catch code to telerik.grid.js:
                success: $.proxy(function(data) {
                    try {
                        data = eval("(" + data + ")");
                    }
                    catch (err) {
                            $t.trigger(this.element, 'error', { errorMsg: "invalid data" });
                            return;
                    }
                    ...
The OnError event will be triggered and I can assume that the 'invalid data' error is due to session timeout.
It would be better if you guys come up with a better solution in the next release so that I don't have to add my patch again.

Regards,
Richard




Tags
Grid
Asked by
Richard Guo
Top achievements
Rank 1
Share this question
or