【发布时间】:2016-08-16 20:43:38
【问题描述】:
我正在尝试从我的 .asmx Web 方法中取回一些数据,但它在 ajax 调用中失败了。这是我的一些 JS 代码:
// BaseCompositeView is basically an object extended from Marionette.CompositeView
MyListView = App.Base.Objects.BaseCompositeView.extend({
// contents removed for brevity
});
// BaseModel is basically an object extended from Backbone.Model
MyListView.Model = App.Base.Objects.BaseModel.extend({
// nothing here
});
// BaseCollection is basically an object extended from Backbone.Collection
MyListView.Collection = App.Base.Objects.BaseCollection.extend({
url: "../WebServices/MyService.asmx/GetUsers",
model: MyListView.Model,
initialize: function(options) {
this.options = _.extend({}, this.defaults, this.options);
this.options.data = JSON.stringify({
"groupID": parseInt(App.Prop.get("GroupID"), 10)
});
}
});
var group_users_view = new MyListView({
tagname: "div",
model: new MyListView.Model(),
collection: new MyListView.Collection()
});
我的 web 方法 GetUsers 有 1 个参数,一个名为 groupID 的整数。根据这个页面:http://backbonejs.org/#Collection-constructor,在创建Collection时会调用MyListView.Collection里面的initialize方法,这发生在MyListView被实例化的时候。
错误发生在文件 jquery-1.12.3.js 中的以下行:
xhr.send( ( options.hasContent && options.data ) || null );
这里,options.data 是undefined。但是 options 的 url 属性是正确的。那么为什么 jquery ajax 不能识别我传入的数据呢?
【问题讨论】:
标签: jquery ajax backbone.js asmx marionette