0
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

kumarz
  • 45
  • 6
  • check the http request when making the POST request (I recommend using Chrome, opening the dev tools, and looking for the request on the network tab.) This will give you more information as to what's happening with your request. – kinakuta Apr 30 '13 at 06:43
  • Ya, I came to know about the pending status through Chrome only, after the submit, it remains in pending, and when I refresh, the data gets saved in the database, but the error callback gets called. – kumarz Apr 30 '13 at 06:51
  • Have you tried using fiddler? – Justin Apr 30 '13 at 19:25

1 Answers1

2

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.

whitmore
  • 21
  • 2
  • Thank you! The backend, a node server in my case, wasn't sending a response. I fixed the issue using the method res() – kumarz May 16 '13 at 07:03