jQuery UI dialog and Ajax POST in asp.net

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

            }
        });

    

Answers


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...


Need Your Help

Git-Tfs sending the wrong identity to tfs during shelve

git tfs git-tfs

When I try to shelve my changes from git-tfs using the command git tfs shelve MY_SHELVE_NAME, I get the following error:

Is it possible to set a data trigger when it is not a value?

c# wpf datatrigger

I have a check box that I want to collapse when a value is any value except one.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.