2

我有一个fetch()在回调函数中$.post()。从fetch()后端抓取数据并更新集合就好了,但是当它运行它successerror回调时,什么都没有发生!我将console.log()s 放在它的两个回调中,它们从未出现在 Javascript 控制台中。

知道发生了什么吗?

视图中的方法

create_set: function() {
    var self = this;

    // Post data to server
    $.post('api/create_set', {
        user_id: $('#user_id').val(),
        post_id: this.post_id,
        set_name: $('#new_set_name').val()
    }, function() {

        // Update list of Sets
        self.setList.fetch({
            data: {
                user_id: $('#user_id').val(),
                post_id: this.post_id
            },
            processData: true
        }, {
            success: function() {
                // Highlight the first class in list
                $(self.setListView.el).children('div:first').addClass('active');
                console.log('success'); // DOESNT RUN!
            }
        }, {
            error: function() {
                console.log('error');  // DOESNT RUN!
            }
        });

        console.log('hello');  // RUNS!

    });
}
4

1 回答 1

4

success并且error应该是options您传递给的对象的属性fetch,您不必为它们创建单独的对象:

self.setList.fetch({
  data: {...},
  processData: true,
  success: function(){...},
  error: function(){...}
})
于 2012-07-24T13:02:55.347 回答