Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
I want to use an ajax call to check if Boolean is true or false.
here is my web method:

C#
[WebMethod]
     public Boolean Login(string uname, string password)
     {


         if (ValidateUser(uname, password))
         {
             FormsAuthentication.Authenticate(uname, password);
             return true;
         }
         return false;
     }


and here is my ajax call but its not working
$(document).ready(function () {
       $('#btnLogin').click(function () {
           var username = "test"
           var password = "1234"
           $.ajax({
               type: "POST",
               contentType: "application/json; charset=utf-8",
               url: "wsLogin.asmx/Login",
               data: "{uname: '" + username + "'" + ",pwd: '" + password + "' }",
               dataType: "Json",
               success: function (success) {

                   alert("Boolean True");
               },
               error: function (error) {

                   alert("Boolean False");
               }
           });
       });
   });
Posted
Comments
Faisalabadians 27-Feb-14 6:40am    
you won't get any compilation error? As far as I know web method should be statics.

1 solution

You want to examine success.d. So check success.d.toString() === "true"; for example.

Also, I would rename your success variable just in case it gets confused.

For example, success: function (result) { and then you would check result.d
 
Share this answer
 

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



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