部署后未触发带有Ajax的静态Web方法

时间:2018-08-14 06:54:09

标签: asp.net ajax

我添加了一个静态Web方法并通过Ajax调用,在本地它可以正常工作,但是部署的服务器没有被触发并且没有显示任何其他错误。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
function EmailCheck() {            
            $.ajax({  
                type: "POST",  
                url: "Application.aspx/CheckEmail", 
                data: '{useremail: "' + $("#<%=txtEmail.ClientID%>")[0].value + '" }',
                contentType: "application/json; charset=utf-8",  
                dataType: "json",  
                success: OnSuccess,  
                failure: function (response) {  
                    alert(response);  
                }  
            });  
        } 

方法是

<System.Web.Services.WebMethod> _
      Public Shared Function CheckEmail(ByVal useremail As String) As String
        Dim retval As String = ""
        Dim con As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString1").ToString())

        con.Open()
        Dim cmd As SqlCommand = New SqlCommand("select Email from EmailTable where Email=@UserEmail", con)
        cmd.Parameters.AddWithValue("@UserEmail", useremail)
        Dim dr As SqlDataReader = cmd.ExecuteReader()

        If dr.HasRows Then
            retval = "true"
        Else
            retval = "false"
        End If

        Return retval
    End Function

而控制权是

<asp:TextBox ID="txtEmail" class="entryCell" runat="server" TabIndex="8"  Width="220px" maxlength="50" onchange="EmailCheck()"></asp:TextBox>  

在部署IIS时应该做什么?

谢谢。

1 个答案:

答案 0 :(得分:0)

我已出于调试目的修改了您的问题,请尝试将其赋予异常

function EmailCheck() {            
            $.ajax({  
                type: "POST", 
              cache: false,
              async: true, 
                url: "Application.aspx/CheckEmail", 
                data: '{useremail: "' + $("#<%=txtEmail.ClientID%>")[0].value + '" }',
                contentType: "application/json; charset=utf-8",  
                dataType: "json",  
                success: function (response, type, xhr) {
         var retVal = JSON.stringify(response);
        alert("Working");
//                            alert(response.d);
        window.alert(JSON.parse(retVal).GetJSONDataResult);
    },
    error: function (xhr) {
        window.alert('error: ' + xhr.statusText);
    }
            });  
        }