[英]Backbone.js fetch callback
I'm using Backbone.js and using fetch with options, but it doesn't seem to get the error or success callbacks, however data is being returned.我正在使用 Backbone.js 并使用带有选项的 fetch,但它似乎没有得到错误或成功回调,但是正在返回数据。
this.user.fetch({data: {username : this.username.val(), check : 'true'}}, {
error: function(model, response) {
console.log(response);
},
success: function(model, response) {
console.log(response);
}
});
This is what I have setup, am I missing something?这是我的设置,我错过了什么吗? It never hits error or success, but it does do the ajax request and it's returning data.它永远不会遇到错误或成功,但它确实会执行 ajax 请求并返回数据。
Thank you!谢谢!
You're passing 2 separate arguments to fetch
.您将 2 个单独的 arguments 传递给fetch
。 Combine them into a single object with data
, success
, and error
fields and it should work for you.将它们组合成一个带有data
、 success
和error
字段的 object ,它应该适合你。
Example for x1a4 answer x1a4 答案示例
var myModel = new MyModel({id: modelId}); myModel.fetch({ success: function (model) { console.log('success: model fetched'); }, error: function () { console.log('error: loading model'); } });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.