无效的Web服务调用,缺少参数值,但我将其包含在调用中

Pet*_*ter 2 asp.net ajax jquery webmethod

我完全被困惑了.我有一个我想通过javascript调用的WebMethod.很简单,使用jQuery,我之前已经完成了这个.然而这一次,我收到一个错误,指出我没有提供WebMethod的论据.但在我看来,我是.

我在我的aspx代码隐藏中有这个:

<WebMethod(True)> _
<ScriptMethod(UseHttpGet:=True)> _
Public Shared Function GetTimes(ByVal input as String) As Object()
    Dim result As New List(Of Object)
    result.Add(New With {.Text = "5:30", .Value = "1"})
    result.Add(New With {.Text = "6:00", .Value = "2"})
    result.Add(New With {.Text = "6:30", .Value = "3"})
    result.Add(New With {.Text = "7:00", .Value = "4"})
    Return result.ToArray
End Function
Run Code Online (Sandbox Code Playgroud)

这在我的javascript中:

$.ajax({
        url: 'ThePage.aspx/GetTimes',
        contentType: "application/json; charset=utf-8",
        data: '{"input":"test"}',
        dataType: 'json',
        succes: function (result) {
            alert('yep');
        },
        error: function (request, errorType, obj) {
            alert('nope');
        }
    });
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

无效的Web服务调用,缺少参数值:\ u0027input\u0027.

StackTrace包括:

在System.Web.Script.Services.WebServiceMethodData.CallMethod(对象目标,IDictionary'2参数)在System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(对象目标,IDictionary'2参数)在System.Web.Script.Services .RestHandler.InvokeMethod(HttpContext的上下文中,WebServiceMethodData methodData,IDictionary`2 rawParams)在System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext的上下文中,WebServiceMethodData methodData)

ExceptionType:System.InvalidOperationException

有人见过这个吗?

Moh*_*lli 5

您似乎正在将文字对象作为字符串.数据应该是{input:"test"}而不是'{"input":"test"}'

所以正确的电话会是

$.ajax({
        url: 'ThePage.aspx/GetTimes',
        contentType: "application/json; charset=utf-8",
        data: {input:"test"},
        dataType: 'json',
        succes: function (result) {
            alert('yep');
        },
        error: function (request, errorType, obj) {
            alert('nope');
        }
    });
Run Code Online (Sandbox Code Playgroud)