0

このコードはhttps://github.com/ccoenraets/backbone-cellarから入手しました。Slim.phpを使用してデータベースに新しいモデルを追加しようとすると、「エラーこのアイテムを追加しようとしたときにエラーが発生しました」と表示されます。しかし、私がフェッチ、更新、削除しようとしているときは、うまく機能しています。追加時にのみエラーが表示されるのはなぜですか?

bootstrap / js / views / 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;
    }

});

本当にありがとう

4

1 に答える 1

0

サーバーが送り返すエラー応答を確認する必要があります。Firebug/Firefox、Chrome などを使用して、追加要求に対するサーバーの応答を確認できます。console.logまたはalert、URL (バックボーン内など) があれば、通常どおりに参照することができます。いずれにせよ、サーバーが不満を持っていることを確認したら、問題を解決できるはずです.

于 2013-01-06T18:05:28.090 に答える