【问题标题】:webmethod shows 500 (Internal Server Error)webmethod 显示 500(内部服务器错误)
【发布时间】:2014-07-14 05:50:14
【问题描述】:

我正在尝试从 alertBook.aspx.vb 调用网络方法。 但是每次单击按钮时都会收到错误 500(内部服务器错误)。

这是从 javascript 调用 webmethod 的正确方法吗? 我是 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

【问题讨论】:

  • 您是否尝试过调试您的网络方法?

标签: javascript asp.net vb.net webmethod


【解决方案1】:

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

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

xhr.responseText 包含有关 ajax 错误的详细信息。
获取更多细节或错误并相应地更改您的代码。

【讨论】:

  • 有没有办法捕获异常并自定义xhr.responseText消息?
猜你喜欢
  • 1970-01-01
  • 2013-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-29
  • 2023-03-05
相关资源
最近更新 更多