“未知的Web方法” Ajax错误

时间:2018-07-31 16:55:00

标签: asp.net ajax vb.net webmethod

在错误函数中返回的数据是:未知的Web方法IncrementTable(pageNumber)。参数名称:methodName。我确定我在某个地方犯了一个小错误,但是希望第二只眼睛可以帮助我找到它。 :)

我的.aspx页面如下:

import { Component, OnInit } from '@angular/core';
import { Transaction } from '../models/transaction';
import { TransactionService } from '../services/transaction.service';
import { DataSource } from '@angular/cdk/table';
import { Observable } from 'rxjs';

@Component({
  selector: 'app-transaction-history',
  templateUrl: './transaction-history.component.html',
  styleUrls: ['./transaction-history.component.css']
})
export class TransactionHistoryComponent implements OnInit {

  dataSource = new TransactionDataSource(this.transactionService);

  displayedColumns = ['id', 'cust', 'mgrName', 'dept', 'timestamp'];

  constructor(public transactionService: TransactionService) { }

  ngOnInit() {
  }
}

export class TransactionDataSource extends DataSource<any>{
  constructor(private transactionService: TransactionService) {
    super();
  }
  connect(): Observable<Transaction[]> {
    return this.transactionService.getUploaded();
  }
  disconnect() { }
}

JavaScript如下所示:

<%@ Page Title="TouchStoneTV" Language="VB" AspCompat="True" AutoEventWireup="True" Debug="True" EnableEventValidation="True" ValidateRequest="False" Trace="False" EnableViewState="True" %>

<%@ Import Namespace="System.Web.Services" %>
<%@ Import Namespace="System.Web.Script.Services" %>

<WebMethod()> _
Public Shared Function IncrementTable '(ByVal PageNumber As Integer)

Dim PageNumber As Integer = 1
For x As Integer = 0 To Math.Ceiling(RowsPerPage/CellsPerRow)

    Dim r As TableRow = New TableRow
    'If (x Mod CellsPerRow) = 0 Then r = New TableRow
    r.Attributes.Add("style","text-align:center;height:200px;width:50%;")

    Dim c1, c2 As New TableCell
    c1.Attributes.Add("style","border:1px solid #000;")
    c2.Attributes.Add("style","border:1px solid #000;")
    c1.Controls.Add(New LiteralControl(PageNumber.ToString & "a : " & x.ToString))
    c2.Controls.Add(New LiteralControl(PageNumber.ToString & "b : " & x.ToString))
    r.Cells.Add(c1)
    r.Cells.Add(c2)

    MainContentTable.Rows.Add(r)

Next x

Return "test"

End Function

2 个答案:

答案 0 :(得分:1)

该方法配置为使用httpget进行调用,但是您正在使用POST方法在javascript中进行调用。

<WebMethod()> _
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)> _
Public Shared Sub IncrementTable(ByVal PageNumber As Integer)
  'code
End Sub

只需删除UseHttpGet:= True,它就可以解决您的问题。或更改jquery ajax代码以使用GET请求并将参数作为querystring传递

答案 1 :(得分:0)

删除参数:

var webMethodUrl = 'Mobile.aspx/IncrementTable';