骨干网是否可以与asp.net soap webservice方法接口以保存和检索数据?因为我从web方法得到了这个错误,但实际上POST
包含参数。
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static Dummy SaveDummy(Dummy myDummy)
{
Dummy dumdum = myDummy;
HttpContext.Current.Session["data"] = dumdum;
return myDummy;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public static Dummy FetchDummy()
{
return (Dummy)HttpContext.Current.Session["data"];
}
public class Dummy
{
private string _name;
private string _script;
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Script
{
get
{
return _script;
}
set { _script = value; }
}
}
window["model"] = Backbone.Model.extend({
initialize: function () {
console.log("CREATED");
},
defaults:{
name:"Please enter your name",
script:"Hello World"
},
urlRoot: "index.aspx/SaveDummy",
validate: function (attrs) {
}
});
$("document").ready(function () {
var myModel = new model({
name: "Stack Overflow",
script: "alert('Hi SO')"
});
var myView = new view({
model: myModel,
el: $("#placeholder")
});
console.log("SAVING");
myModel.save();
console.log("FETCHING");
myModel.fetch();
{"name":"Stack Overflow","script":"alert('Hi SO')"}
Invalid web service call, missing value for parameter: 'myDummy'.
我确实调查了其他类似问题的帖子,这些帖子通过做类似的事情来解决
{myDummy={"name":"Stack Overflow","script":"alert('Hi SO')"}}
。如何使用Backbone生成这个?
答案 0 :(得分:2)
Backbone中的所有服务器端同步都是通过Backbone.Sync处理的,后者专为两件事而设计:
因此,您需要覆盖Backbone.Sync行为以与后端通信。它看起来相对简单。可以在以下链接中找到一些指导: