Backbone.js 500 Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings backbone error handling and policies of this site About Us Learn more about Stack Overflow
Backbone Error Event
the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation backbone model error handling Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it
Backbone Save Error Handling
only takes a minute: Sign up Global error handler for backbone.js ajax requests up vote 33 down vote favorite 14 Is there way to bind one error handler for ajax requests that performs by backbone.js? My situation: I can get 401 (Unauthorized) at any time, so I need to show login popup. javascript rest backbone.js share|improve this question asked May backbone sync 27 '11 at 9:47 Plastic Rabbit 6692821 add a comment| 4 Answers 4 active oldest votes up vote 23 down vote accepted Use jQuery directly for this. $(document).ajaxError(function (e, xhr, options) { // do your stuff }); You can do the same thing for CSRF in rails for exemple (using ajaxSend). You can read more here: http://api.jquery.com/jQuery.ajax#advanced-options share|improve this answer edited Jul 20 '13 at 10:27 smhg 1,1781021 answered May 27 '11 at 16:08 Julien 8,42243037 7 Note that this callback will execute for all jQuery ajax errors, not just those related to backbone requests. There may be other libraries in the page making ajax requests via jquery, you probably don't want the callback in those cases. –cerberos Apr 11 '13 at 13:14 1 hm, that's a way too global... –wik Dec 4 '13 at 13:21 3 This approach of using global ajaxError callback does not work with Backbone models/collections if the fetch, sync, create methods have a error callback provided as the option. –Nilesh Kale Jan 22 '14 at 6:53 2 -1 this
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack
Backbone Model Save
Overflow the company Business Learn more about hiring developers or posting ads with us
Backbone Fetch
Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a backbone router community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Manage of server error response with backbone up vote 17 down vote favorite 4 I http://stackoverflow.com/questions/6150514/global-error-handler-for-backbone-js-ajax-requests would like to know the best way to manage server error response on new, update or delete models. At this moment the server returns a http status code # 400. But the default error handler in Backbone is not showing the errors. How can i show these errors? Is it ok that the server returns http error headers when a server side validation fails? (Maybe is better return a success response http://stackoverflow.com/questions/12148333/manage-of-server-error-response-with-backbone with a status='ERROR' message) backbone.js error-handling share|improve this question asked Aug 27 '12 at 19:28 Jaime Rivera 4032820 add a comment| 1 Answer 1 active oldest votes up vote 19 down vote accepted If you're returning an http status other than 2XX, you're already half way done with the job. :-) Basically, what you can do is send back anything you want back as the response. For example, you might just send back something like this: // Send back http status 500 echo 'Could not save, server error'; The 500 status will trigger the Backbone error callback and your response is a jqXHR object. In the above example you can get the message by doing something like this in your error callback. model.save({},{ error: function(model, response) { console.log(response.responseText); } }); This is the simplest way to get back some data/message about the error that happened server side. You can of course, create more sophisticated data to be returned from the server: // I'm using SLIM RESTful framework... $dataOut = array('error'=>'Validation type', 'message'=>'Did not validate'); $response->body(json_encode($dataOut)); In the same fashion, you can access that response like so: model.save({},{ error: function(model, response) { var responseObj = $.parseJSON(response.responseText); console.log('Type: ' + responseObj.error + ' Message: ' + responseObj.message); } }); Or something alon
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about http://stackoverflow.com/questions/11223516/showing-500-internal-server-error-using-backbone-js-with-slim-php-when-only-ad Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Showing 500 (Internal Server Error) using backbone.js with slim.php when only adding new model error handling up vote 1 down vote favorite 1 I got this code from https://github.com/ccoenraets/backbone-cellar as I am trying to learn backbone.js. When I am trying to add new model to database using slim.php, it is showing 500 (Internal Server Error). But when I am trying to fetch, update, delete its working good. Why it is showing error only on adding ? Plz help me, Thanks. window.WineView = Backbone.View.extend({ initialize: function () backbone.js 500 error { this.render(); }, render: function () { $(this.el).html(this.template(this.model.toJSON())); return this; }, events: { "click .save" : "beforeSave", "click .delete" : "deleteWine" }, beforeSave: function () { var self = this; var check = this.model.validateAll(); if (check.isValid === false) { utils.displayValidationErrors(check.messages); return false; } // Upload picture file if a new file was dropped in the drop area if (this.pictureFile) { this.model.set("picture", this.pictureFile.name); utils.uploadFile(this.pictureFile, function () { self.saveWine(); } ); } else { this.saveWine(); } return false; }, saveWine: function () { var self = this; this.model.save(null, { success: function (model) { self.render(); app.navigate('wines/' + model.id, false); utils.showAlert('Success!', 'Wine saved successfully', 'alert-success'); }, error: function () { utils.showAlert('Error', 'An error occurred while trying to add this item', 'alert-error'); } }); }, deleteWine: function () { this.model.destroy({ success: function () { alert('Wine deleted successfully'); window.history.back(); } }); return false; } }); backbone.js share|improve this question asked Jun 27 '12 at 9:51 Nag 6429 2 well Internal server error means that an internal server error has occurred (aka your server just went down), so the error originates from your server. So can you post the code for you slim server, especially the code concerning ADDING items? –jakee Jun 27 '12 at 13:50 Also would be interesting to