2

In the example below, how can i post data to webservice after clicking login button in asp.net?

 

        $(document).ready(function () {
        var username=$("#username").val();
        var password=$("#pass").val();

            $("#dialog").dialog({
                bgiframe: true,
                autoOpen: false,
                height: 400,
                width: 300,
                modal: true,
                buttons: {
                    "Cancel": function () {
                        $(this).dialog("close");
                    },
                    "Login":function() {
                    $.ajax(
                    {
                    type:"POST",
                    dataType:"json",
                    url:"WebService.asmx/Login",
                    contentType:"application/json",
                    data:"{username:'"+username+"',password:'"+password+"'}",
                    success:function(val)
                    {
                    $("#isValid").attr("value",val.d);
                    }}
                    );
                    },
                },
            });

            var isValid = $("#isValid").val();
            if (isValid== "false") {
                // Display the modal dialog.
                $("#dialog").dialog("open");

            }
        });

    
7
  • 1
    Can you add an "error:" property to your .ajax call and get the error information and post it here? It's difficult to determine what your issue is without more information. Commented Nov 30, 2010 at 15:41
  • @Charles Boyoung:My requirement is to post data to webservice after clicking the login button Commented Nov 30, 2010 at 15:51
  • @santosh - and what isn't working? Doing what I said will give you an error message that will help determine why what you have isn't working. Commented Nov 30, 2010 at 15:57
  • @Charles:After clicking login button i want to post the value of two text boxes named username and password to webservice. Commented Nov 30, 2010 at 16:02
  • 1
    @santosh - how do you know you aren't getting an error? You aren't using the "error" property in your ajax call, which means that any errors are just getting lost. See api.jquery.com/jQuery.ajax and look at the error property to see how to use it. Commented Nov 30, 2010 at 16:10

1 Answer 1

1

If you have the following signature on your WebService...

function bool Login(string userName, string password)

You just need to provide a javascript object in the JSON-notation that looks like this:

{ "userName" : "Admin", "password": "1234" }

Hint: make sure that the names in the javascript object do have the same name and casing... Makes life much easier.

Hope I understood your question correctly...

Sign up to request clarification or add additional context in comments.

3 Comments

I am looking for postback after button click
What exactly is your problem? You're not being very clear. This should've answered your question.
@gAMBOOKa:My requirement is to post data to webservice after clicking the login button

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.