0

I am currently working on a small Restful CRUD app, the frontend for which is written using the backbone.js framework. I understand most of the internals of how this application is working and its MVC structure, however I have several models, which when they are being edited, redirect unnecessarily. Perhaps a code example will help:

updateUser: function () {
        this.model.save(null, {
            success: function (model) {
                app.navigate('userlist', {trigger: true, replace: true});
                utils.showSuccessAutoClose("User", "The user has been updated.");
            },
        error : function (model, fail, xhr) {
            utils.showCommsError(fail.status, fail.responseText);
        }
        });
}

The issue that I have is when this update method fails (when the server returns a 500 server for whatever reason), the page redirects from the current page

/pages/admin.jsp#useradd to /pages/admin.jsp for no reason, even if all of the code in the error handler commented out.

What is causing this redirect to happen?

Husman
  • 6,819
  • 9
  • 29
  • 47
  • You might want to inspect the HTTP response headers in Firebug or your favorite browser debugging tool. Maybe the server is sending back a "Location" header? Also, if you are getting a 500 error back, you can treat this as a catastraphic error. A 400 or 422 response is good for validation errors. See http://stackoverflow.com/questions/3290182/rest-http-status-codes – Greg Burghardt Dec 17 '13 at 17:08
  • I cannot change the (outdated) web services unfortunately, the 500 in this case means a username already exists but it is not catastrophic. I have already inspected the error response in firebug and it is a just a json object with the error title and error message. No js is sent back, so it looks like backbone is being a pain in the back and redirecting for some reason. – Husman Dec 17 '13 at 17:34

0 Answers0