【问题标题】:Ajax call: Invalid web service call, missing value for parameter: 'itemTypes'Ajax 调用:Web 服务调用无效,参数缺失值:“itemTypes”
【发布时间】:2020-07-28 15:16:07
【问题描述】:

我创建了一个 ajax 调用并试图将一个对象作为参数发送到服务器,但我收到以下错误:

Invalid web service call, missing value for parameter: 'itemTypes'

我检查了 javascript 中的 itemTypes 变量,它包含预期值:

sessionStorage.itemTypeUid = "18"

sessionStorage.itemTypeName = "TABLE_NAME"

args = {CurId: 18, BaseTableName: "TABLE_NAME"}

javascript:

var itemTypes = {
            CurId: parseInt(sessionStorage.itemTypeUid),
            BaseTableName: sessionStorage.itemTypeName
        };

        aj("DeleteItem", itemTypes);

阿贾克斯:

function aj(funcName, args) {
    retval = $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: 'ItemEdit.asmx/' + funcName,
        data: JSON.stringify(args),
        dataType: "json",
        error: function (a, b, c) {
            var errors = a + b + c
        }
    });
}

VB:

<WebMethod()>
    Public Sub DeleteItem(itemTypes As Object)
    
            Dim CurId = ""
            Dim BaseTableName = ""
    
            actions.DeleteItem(CurId, BaseTableName)
        End Sub

【问题讨论】:

  • 这里的sessionStorage 变量是什么?
  • sessionStorage.itemTypeUid = "18", sessionStorage.itemTypeName = "GRIT_SALT_BINS", args = {CurId: 18, BaseTableName: "GRIT_SALT_BINS"}
  • 那么,sessionStorage 是这里的对象吗?
  • @palaѕн 抱歉,没有回答您的问题。是的,会话存储是一个有一堆值的对象
  • 现在可以使用了。我没有注意到 sub 说 CurID 而不是 CurId,所以您的解决方案确实有效,非常感谢您的帮助。

标签: javascript asp.net ajax vb.net webmethod


【解决方案1】:

您可以像这样更新您的网络方法:

<WebMethod()>
Public Sub DeleteItem(CurId As Integer, BaseTableName As String)
   actions.DeleteItem(CurId, BaseTableName)
End Sub

请确保此处的参数名称与 ajax 调用中传递的值完全相同。即使名称相同但大小写不同,也可能会出错。因此,请先仔细检查变量名称。另外,删除

Dim CurId = "" 
Dim BaseTableName = "" 

从方法中,这样就不会有名字冲突了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多