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

4

1 回答 1

2

我相信您的 POST 挂起的原因是它还没有收到服务器的回复。即使到达服务器并处理了请求,如果它没有传回HTTP 状态代码,您的前端将保持挂起状态,直到它返回。

检查您的后端并确保您的 AJAX PUT、POSTS 和 DELETE 正在返回 HTTP 状态代码。成功调用的一个很好的起点是返回状态码 200,这意味着好的,一切都很好。对于失败,有旧的备用,状态代码 500“内部服务器错误”。还有更多可供选择,所以选择一个适合的。

希望有帮助。

于 2013-05-09T01:56:21.257 回答