当我将数组数据发布到Web方法时,我们得到的错误就像这样内部服务器错误(500)

时间:2017-02-20 10:33:05

标签: jquery ajax

这是我的ajax

$.ajax({
    type: "POST",
    url: "WebForm4.aspx/StatusUpdate",
    data: '{"idArray":"' + JSON.stringify(x) + '","Status":"' + Rstatus + '"}',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (response) {
        location.reload();
    },
})

网络方法

 Public Shared Function StatusUpdate(ByVal idArray() As String, Status As String) As String
 Dim strargument As New StringBuilder()
        Try
            Dim cnt As Int16 = idArray.Length()
            For i As Int16 = 0 To cnt - 1
                If i = cnt - 1 Then
                    strargument.Append("'" & idArray(i) & "'")
                Else
                    strargument.Append("'" & idArray(i) & "',")
                End If
            Next

            Using cmd As New SqlCommand("Update [ERP_EmployeeRole] SET Status=@Status where RoleID in (" & strargument.ToString & ")")
                cmd.Connection = con
                cmd.Parameters.AddWithValue("@Status", Status)
                con.Open()
                cmd.ExecuteNonQuery()
                Dim s1 As String = "Status updated"
                Return s1
            End Using

1 个答案:

答案 0 :(得分:0)

构建要发送到服务器的Json数据的方式似乎存在问题。

我建议你创建一个类来定义一个字符串数组,即idArray和另一个字符串属性Status,就像我在下面定义的类一样。我将使用您将能够转换为VB的C#版本。

public class SomeClass
{
   public string Status { get; set; }
   public string IdArray[] { get; set; }
}

在客户端,您可以将其用作

var SomeObj = { Status: "Some Status", IdArray: YourArray }

在将其发送到服务器之前,您应该使用:

JSON.stringify({"someObj":SomeObj});

并且在您的Web方法中,您应该使用类似这样的内容

public static YourMethod(SomeClass SomeObj)
{
    //TODO: Do Something here with your object
}
相关问题