我想做的是从aspx.vb调用WebMethod,下面是Default.aspx.vb中的WebMethod语法
<System.Web.Services.WebMethod()> _
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)> _
Public Shared Function dat( _
ByVal Id As Integer) As List(Of items)
Dim eve As New List(Of items)()
eve = (From row In getItems(Id).Rows
Select New items With {
.Name = row("Name").ToString(),
.Description = row("Description").ToString(),
.ItemPic_url = row("ItemPic_url").ToString()}).ToList()
Return eve
End Function
Run Code Online (Sandbox Code Playgroud)
以下是我从中调用Web方法的jquery函数:
注意:我的Jquery函数位于我的母版页中,我从启动Default.aspx页调用它。
function getItems() {
$("#tbody").empty();
var id = $("select")[0].value;
$.ajax({
url: "Default.aspx/dat",
data: { Id: id },
contentType: "Application/json; charset=utf-8",
responseType: "json",
method: "POST",
success: function (response) {
$("#tbody").empty();
var rows …Run Code Online (Sandbox Code Playgroud)