2012-07-24 91 views
2

我在回调函数$.post()中有fetch()fetch()从后端抓取数据并更新集合,但是当它运行successerror回调时,没有任何反应!我在其回调中放置了console.log() s,并且它们从未出现在Javascript控制台中。fetch()未调用其成功和错误回调函数(backbone.js)

任何想法发生了什么?

在视图的方法

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

successerror应该是options对象,你传递给fetch的属性,你不必为它们创建单独的对象:

self.setList.fetch({ 
    data: {...}, 
    processData: true, 
    success: function(){...}, 
    error: function(){...} 
})