Ajax调用没有返回错误

时间:2016-02-17 15:01:08

标签: asp.net ajax

我在客户端有一些像这样的ajax代码:

$.ajax({
                type: "POST",
                url: "frmPNList.aspx/ChangeGroupOfUSNs",
                async: false,
                contentType: "application/json; charset=utf-8",
                //data: '{strNewUSN: "' + usn.value + '", strURNs: "' + id[1] + '", strDatasetName: "' + id[2] + '", strCon: "' + $("#<%=fieldGenieConnectionString.ClientID%>")[0].value + '"}',
                data: '{strNewUSN: "' + usn.value + '", arrayURNDataset: ' + JSON.stringify(strURNDataset) + ', strCon: "' + connectionstring.value + '", strUserNameLocal: "' + username.value + '"}',
                //data: '{strNewUSN: 9, strURNs: 1, strDatasetName: 2}',
                dataType: "json",
                success: OnSuccess(),
                error: function (xhr, errorType, exception) {
                    var errorMessage = exception || xhr.statusText; //If exception null, then default to xhr.statusText
                    alert("there was an error changing the USN of the group: " + errorMessage);
                },
                failure: function () {
                    alert('there was an error changing the USN of the group.')

                }
            });

            function OnSuccess() {
                return function () {

                }
            }
            //end of AJAX call

并在服务器端:

    <System.Web.Services.WebMethod()> _
        Public Shared Sub ChangeGroupOfUSNs(ByVal strNewUSN As String, ByVal arrayURNDataset As String, ByVal strCon As String, ByVal strUserNameLocal As String)
Try
            Throw New Exception
        Catch ex As Exception

        End Try
    End Sub

未调用失败消息。这是为什么?

1 个答案:

答案 0 :(得分:2)

只有在请求本身出现问题时才会触发失败(错误404,错误500等)。它不会返回PHP / ASP错误。

如果你想检查PHP / ASP错误,你必须自己做(在完成函数中你可以创建一些if语句)。