Jump to content

Edit Backbone Ajax Success Method to Add in Custom Error Handling


unemployment

Recommended Posts

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.