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

How to create obfuscatable variables and functions in a javascript module?

javascript module obfuscation

I have a set of js files I concatenate into a unique file at compile time, before running YUI compressor on it (all under maven).

The simpliest way to visualize - easy-use graphics. Which languages and lib?

c++ windows graphics visualization

I'm going to develop math model of trafics simulation and will need to somehow vizualise it. The model will be in C++

SizeToContent paints an unwanted border

c# wpf sizetocontent

Whenever I try to make a window and I set the SizeToContent to WidthAndHeight, on opening the window correctly sizes to it's contents, but it adds a small border to the right and the bottom. On res...