gpt4 book ai didi

javascript - 如何使用Backbone Js调用asmx web服务进行采集

转载 作者:行者123 更新时间:2023-12-02 19:56:11 25 4
gpt4 key购买 nike

我希望有人能让我通过代码学习从主干集合中调用 asmx webservices。我在这里放的例子非常简单

集合

 window["Persons"] = Backbone.Collection.extend({
model: Person,
url: "service.asmx/GetPeople"
});

注意:我现在确实有一个 service.asmx 文件

Asmx 端点

 [WebMethod]
[ScriptMethod]
public static List<Person> GetPeople()
{
List<Person> people = new List<Person>(10);
for (int i = 0; i < 10; i++)
{
people.Add(new Person(i.ToString()));
}
return people;
}

模型

public class Person
{
public string Name { get; set; }
public Person(string name)
{
Name = name;
}
}

当我执行以下操作时,chrome xhr 检查器会通知我此错误

var family = new Persons();family.fetch();

Request format is unrecognized for URL unexpectedly ending in '/GetPeople'

最佳答案

您将需要重写 Backbone.sync() 函数来自定义模型的持久性和从服务器检索模型。

您可以查看annotated source code说明如何为本地存储替代方案覆盖 Backbone.sync() 函数。

关于javascript - 如何使用Backbone Js调用asmx web服务进行采集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8607607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com