unemployment Posted February 24, 2013 Share Posted February 24, 2013 I have my own custom error code inside of a backbone ajax success method in case the server returns an error. The problem is that this code is repeated throughout my app and I wanted to edit the success function in one place so I don't have to constantly repeat this error handler in every ajax success. I want to edit the success function to include this error check wrapper. Do you know how to do that? Here is an example of my success method in one of my views: "success" : function success(model, data) { if(data['error'] !== undefined && data['error'].length === 0) { message('error', 'Whoops! System Error. Please refresh your page.'); } else if(data['error'] !== undefined) { message('error', data['error']); } else { //add templates and do stuff here } } Ideally I'd like to set that in a config somewhere and then I'd just be able to use: "success" : function success(model, data) { // add templates and do stuff here } Is this possible? I tried using ajaxSetup but that didn't seem to work for me. Quote Link to comment https://forums.phpfreaks.com/topic/274896-edit-backbone-ajax-success-method-to-add-in-custom-error-handling/ Share on other sites More sharing options...
Jessica Posted February 24, 2013 Share Posted February 24, 2013 define the function, then your success function can either be a plain wrapper for it, or I think you can just send the string name of the function. Quote Link to comment https://forums.phpfreaks.com/topic/274896-edit-backbone-ajax-success-method-to-add-in-custom-error-handling/#findComment-1414713 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.