【发布时间】:2021-12-27 04:01:50
【问题描述】:
我正在尝试在 VB ASP.NET 页面上运行 AJAX Webservice 请求。
当页面加载时,我正在尝试调用 web 服务,但我在控制台中收到 500 错误。
我的 WebService 文件如下所示:
<System.Web.Script.Services.ScriptService()>
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")>
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
<ToolboxItem(False)>
Public Class usrDataSave
Inherits System.Web.Services.WebService
<WebMethod()>
Public Function saydata(abc As String)
MsgBox(abc)
Return abc
End Function
我的 ASP.NET 页面如下所示:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "POST",
url: "usrDataSave.asmx/saydata",
data: "hello_world",
contentType: "application/json",
datatype: "json",
success: function(responseFromServer) {
alert(responseFromServer.d)
}
});
});
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
我希望页面能够加载,并在服务器端弹出一个显示“hello_world”的消息框,并希望 Web 浏览器创建一个显示相同内容的弹出窗口。但是,这不会发生,因为我收到了 500 错误。
我尝试通过使用不同版本的jQuery 以及在web.config 文件中启用请求来解决此问题,如下所示:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
这不起作用,我仍然在 Web 浏览器控制台中看到“服务器响应状态为 500”。应用程序的调试控制台中不会记录任何错误。
我该如何解决这个问题?
【问题讨论】:
标签: javascript jquery asp.net ajax vb.net