2012-07-15 61 views
0

我從https://github.com/ccoenraets/backbone-cellar得到了這段代碼。當我嘗試使用slim.php將新模型添加到數據庫時,它顯示「錯誤嘗試添加此項目時發生錯誤」。但是,當我試圖獲取,更新,刪除它的工作良好。爲什麼它僅在添加時顯示錯誤?問題saveWine using backbone.js

引導/ JS /視圖/ winedetails.js

window.WineView = Backbone.View.extend({ 

    initialize: function() { 
     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; 
    } 

}); 

感謝這麼多

回答

0

你需要看到什麼錯誤響應您的服務器發送回來。您可以使用Firebug/Firefox,Chrome等來查看服務器對您的添加請求的迴應。或者,如果您可以使用console.logalert這個URL(例如從Backbone內部),那麼您可以簡單地瀏覽它。無論哪種方式,一旦你看到你的服務器不滿意你應該能夠解決你的問題。