【发布时间】:2021-04-14 22:55:49
【问题描述】:
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Services.asmx/HelloWorld",
data: "{}",
dataType: "json",
success: function (data) {
alert(data.d);
},
error: function (err) {
alert(err.d);;
}
});
});
当我调用函数HelloWorld 时,它工作正常。但问题是我在这个文件中有多个函数,比如HelloWorld2、HelloWorld3。代码如下:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Script.Services
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Services
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello Admin"
End Function
Public Function HelloWorld2() As String
Return "Hello Manager"
End Function
Public Function HelloWorld3() As String
Return "Hello User"
End Function
End Class
如何调用HelloWorld2 函数,例如:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Services.asmx/HelloWorld2",
data: "{}",
dataType: "json",
success: function (data) {
alert(data.d);
},
error: function (err) {
alert(err.d);;
}
});
【问题讨论】:
-
你的函数看起来都一样,你的调用看起来都一样,所以你可以用同样的方式调用其他函数。您面临的具体问题是什么?
标签: asp.net ajax web-services