0

I have added a static web method and invoke through Ajax, locally it worked fine, but deployed server it is not getting fired and not showing any other error.

<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);  
                }  
            });  
        } 

and method is

<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

and control is

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

while deploying what should I do in IIS?

Thanks in advance.

SSN
  • 1
  • 1

1 Answers1

0

I have modified your question for debugging purpose please try it will give exception if any

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);
    }
            });  
        } 
Pramod
  • 96
  • 7
  • Thank you Pramod, I tried the modified code, but it is not getting fired, so errors are not displaying – SSN Aug 14 '18 at 08:13
  • @SSN I noticed that `EmailAvailability` method is called `onchange` event on asp:textbox but javascript function name is `EmailCheck`may be that is why ajax call is not initiated. Also, after deploying on IIS, check for any console errors in browser developer tools – Mohsin Mehmood Aug 14 '18 at 09:18
  • @Mohsin Mehmood It is a typo...but in the page it was correct. yes, the following error is showing 'asp.net ajax client-side framework failed to load' – SSN Aug 14 '18 at 09:27
  • @SSN switch to network tab on the developer tools and check if any network call is failing specially .axd api calls – Mohsin Mehmood Aug 14 '18 at 09:30
  • It is not showing any network related errors/activities, any extra line to be added to web.config – SSN Aug 14 '18 at 12:39
  • @SSN I believe are using ScriptManager or ScriptManagerProxy on your page which is causing the error `asp.net ajax client-side framework failed to load`. Check this SO thread https://stackoverflow.com/questions/3695351/ajax-client-side-framework-failed-to-load-asp-net-4-0 for possible fix – Mohsin Mehmood Aug 14 '18 at 13:52
  • 1
    @MohsinMehmood, Thank you...Problem solved, It was due to mismatch of .Net framework version in my development machine and deployed server. – SSN Aug 16 '18 at 09:05