Reputation: 45
category = new Category({name: name, img: img});
category.save(null, {
success: function(){
console.log("saved")
},
error: function(){
console.log("error")
}
});
I have a form, and when the submit button is clicked, it captures the name and img data and the code above is run.
However, the POST request remains pending, and is completed only when I refresh the page. Even though the data is saved in the database, an error callback is being called. I don't know what is going wrong here, I'm new to Backbone and I'm using Backbone Relational in this case
Upvotes: 0
Views: 363
Reputation: 21
I believe the reason your POST is pending is because it hasn't heard back from the server yet. Even though the server was reached and processed the request, if it doesn't pass back a HTTP status code your front-end will remain in the pending state until it does.
Check your back-end and ensure your AJAX PUT, POSTS and DELETEs are returning HTTP status codes. A good place to start for a successful call is to return status code 200, which means OK, everything went great. For a fail there's the old standby, status code 500 'Internal Server Error'. There are many more to choose from so pick one out that fits.
Hope that helps.
Upvotes: 2