简体   繁体   English

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

[英]webmethod shows 500 (Internal Server Error)

I am trying to call a webmethod from alertBook.aspx.vb. 我正在尝试从alertBook.aspx.vb调用网络方法。 But I received an error 500 (internal Server Error) whenever I click on button. 但是,每当我单击按钮时,我都会收到错误500(内部服务器错误)。

Is this a right way to call the webmethod from javascript? 这是从javascript调用网络方法的正确方法吗? I am new to javascript. 我是javascript新手。

Thanks in advance. 提前致谢。

My javascript as follow: 我的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 is alertBook.aspx是

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

My webmethod as follow: 我的网络方法如下:

<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

You should look for more detail on the error. 您应该查找有关该错误的更多详细信息。 You can use 您可以使用

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

xhr.responseText contains detail information about the ajax-error. xhr.responseText包含有关ajax错误的详细信息。
do get more detail or the error and change you code accordingly. 获取更多详细信息或错误,并相应地更改代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM