webmethod显示500(内部服务器错误)

webmethod shows 500 (Internal Server Error)

本文关键字:服务器 错误 内部 显示 webmethod      更新时间:2023-09-26

我正在尝试从alertBook.aspx.vb调用webmethod。但是每当我点击按钮时,我收到一个错误500(内部服务器错误)。

这是从javascript调用webmethod的正确方式吗?I am new to javascript.

提前感谢。

我的javascript如下:

function webMethod() {
                setInterval(function () {
                    $.ajax({
                        type: "post",
                        url: "alertBook.aspx/newUid",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (result) {
                            OnSuccess(result);
                        },
                        error: function (xhr, status, error) {
                            OnFailure(error);
                        }
                    });
                }, 3000);
            }
            function OnSucceeded(response) {
                alert(response);
                //pushNoti(response, "info", "y");
            }
            function OnFailure(error) {
                alert(error);
            }

alertBook。aspx是

<a class="btn btn-info" onclick="webMethod()">WebMethod</a>

我的webmethod如下:

<WebMethod()> _
    Public Shared Function newUid(ByVal msg As String) As String
        Dim objForm As New alertBook
        Dim objUtl As New uClass.fUtilities
        Dim sqlQuery As String
        Dim UID1, UID2 As String
        Dim notiStr As String
        Dim objDb As New uClass.dbFunctions("myCon")
        Dim dtRecords As DataTable
        sqlQuery = "select top 1 UID from alertsBook order by UID desc"
        If objDb.getDataTable(dtRecords, sqlQuery) = False Then
            Return objForm.displayMessage("Error", objDb.errDesc)
        End If
        For rCount = 0 To dtRecords.Rows.Count - 1
            UID1 = dtRecords.Rows(rCount)("UID")
        Next
        If UID1 <> UID2 Then
            notiStr = "<script> " & displayNoti("", "info", "New Message", True) & "</script>"
            UID2 = UID1
            'scriptDiv.InnerHtml = notiStr
        Else
            notiStr = ""
        End If
        Return notiStr
    End Function

您应该查找有关错误的更多细节。你可以使用

  error: function (xhr, status, error){
    alert(xhr.status);
    alert(xhr.responseText);
  }

xhr.responseText包含ajax-error的详细信息。
获取更多的错误细节,并相应地修改代码。