Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ASP.net 中有没有一种方法可以使用 Jquery Ajax 方法从数据库中获取数据。我知道我可以通过创建 Web 服务轻松访问数据并使用 Ajax 从那里获取数据。我想知道的是,如何从访问数据库而不是创建 Web 服务的简单类方法中获取数据。
一种方法是编写一个 HTTPHandler 并使用 Jquery 调用该处理程序来检索数据。
看看这是一种超级简单(惰性)的方法,可以直接从你的 aspx.cs 文件中定义的公共方法返回:
asp.net web表单json返回结果
示例显示在方法之上放置[WebMethod]和属性允许您直接从 ajax 客户端请求调用。[ScriptMethod(ResponseFormat = ResponseFormat.Json)]值得考虑保护此方法,以防止来自其他地方的呼叫!
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]