ajax 与 asp.net 通信

deeppocket 2019-06-24 06:52:11
<%@ WebService Language=”C#” Class=”QuotationService” %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Collections.Generic;
[WebService(Namespace = “http://tempuri.org/”)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class QuotationService : System.Web.Services.WebService
{
[WebMethod]
public string GetQuote()
{
List<string> quotes = new List<string>();
quotes.Add(“The fool who is silent passes for wise.”);
quotes.Add(“The early bird catches the worm.”);
quotes.Add(“If wishes were true, shepherds would be kings.”);
Random rnd = new Random();
return quotes[rnd.Next(quotes.Count)];
}
}

ptg
Calling Web Services from the Client 1779
40
})
});
});
</script>
</head>
<body>
<form id=”form1” runat=”server”>
<div>
<input id=”btnGet” type=”button” value=”Get Quote” />
<br /><br />
<span id=”spanQuote”></span>
</div>
</form>
</body>
</html>
...全文
175 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanghui0380 2019-06-25
  • 打赏
  • 举报
回复
无需webservice 只需要在aspx.cs 页面内使用 [WebMethod] 给一个静态公开方法标记一下即可 https://www.cnblogs.com/sxhlf/p/6709264.html
stherix 2019-06-25
  • 打赏
  • 举报
回复
默认webservice只支持SOAP 如果要支持GET/POST https://blog.csdn.net/weixin_34143774/article/details/89750606
正怒月神 版主 2019-06-25
  • 打赏
  • 举报
回复
可以访问的。 不过只是不推荐这么用而已。 https://blog.csdn.net/lovecruel/article/details/6697764
guofeng2000 2019-06-25
  • 打赏
  • 举报
回复
没有Restful能访问吗? 我觉得不能直接通过ajax调用web services。
deeppocket 2019-06-24
  • 打赏
  • 举报
回复
<%@ Page Language=”C#” %> <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml”> <head id=”Head1” runat=”server”> <title>Show Web Service Method</title> <script type=”text/javascript” src=”./Scripts/jquery-1.4.1.js”></script> <script type=”text/javascript”> $(document).ready(function () { $(“#btnGet”).click(function () { $.ajax({ type: “POST”, dataType: “json”, contentType: “application/json”, url: “QuotationService.asmx/GetQuote”, success: function (data) { $(“#spanQuote”).html(data.d); }, error: function () { alert(“The call to the web service failed.”); } CHAPTER 40 Client-Side AJAX with jQuery From the Library of Wow! eBook

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧