Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am not able to call the ajax method when i debug it is jumping from $.ajax({ line. Am i doing any mistake here.Here is my code
JavaScript
$.ajax({
        data: '{UserCode:"' + $('#txtUserName').val() + '",Password:'
                + $('#txtUserName').val() + '"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: onSuccess,
        fail: onFail
    });
}

function buttonClick() {
        CallPageMethod("GetLoginDetails", success, fail);
    }

    function success(response) {
        if (response.d) {
           alert('');
        }

    }

    function fail(response) {
        //alert("An error occurred.");
    }

ASP.NET
<asp:Button ID="btnLogIn" runat="server" Text="Sign In" OnClientClick="return buttonClick();" />
Posted
Updated 20-Jan-16 18:50pm
v7
Comments
Afzaal Ahmad Zeeshan 21-Jan-16 0:29am    
Check the console for any errors.
Sinisa Hajnal 21-Jan-16 2:47am    
You lack url parameter in ajax

<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>

Drag and Drop these lines from your Script folder.
Also add these attributes:

JavaScript
type: "POST",
url: 'UrlName',
data: { "term": request.term },
success: function (data) {
//do something
}

*term is the name of the parameter to the function called in URL
 
Share this answer
 
v3
There are too many things wrong with your code to even list...missing url, wrong content type, not returning false from your click event, passing functions that don't exist.

If I was you I'd google examples of calling services via jQuery ajax and start by getting a basic example working first.

Using jQuery ajax to call asmx webservice methods | The ASP.NET Forums[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900