2

I want to extract form parameters, just like in java request.getParameter("blah")

How to do it in C#, presently I serialized my form with jQuery and sending to web method, there I want to extract it

ajax

$("#btn").click(function () {
            alert($('#login').serialize());
            $.ajax({
                type: "POST",
                url: "Default.aspx/Login",
                data: "{'vals': '" + $('#login').serialize() + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    TINY.box.show({ html: msg.d, animate: false, close: false, mask: true, boxid: 'success', autohide: 3, top: 200, left: 500 });
                }
            });
        });
    });

code-behind

[WebMethod]
        public static string Login(String vals)
        {
           //WHAT TO DO HERE SO THAT I CAN EXTRACT FROM THAT STRING
          return vals;
        }

I can see the data resurned by msg.d at the client, but thats something like this "uname=1&pwd=2". How to extract it?? please some one help me out. Also is there any way to access the webmethod without making it static?

7
  • use json instead of string. or use split('&') and then split('=') you will get the required values. Commented Jan 11, 2013 at 6:16
  • See what i want is something simple, that can be done without changing the client code and with a single line, I have still hope in c#, there will be some method which can do that, not using strings functions. The data it self is sent as query string, then how can i expect it to be in json format. the data is going like this "uname=1&pwd=2" Commented Jan 11, 2013 at 7:04
  • use split function of string dotnetperls.com/split Commented Jan 11, 2013 at 7:08
  • Thankyou for ans me. This means the data which ever i am getting to web method is no more in request its just a string? Please give me and example to send and retrive data in json also that wold be great help Commented Jan 11, 2013 at 7:11
  • the data should look somethink like this, tell if i am wright. Commented Jan 11, 2013 at 7:16

1 Answer 1

1

Use json instead of string.
Here are few links which you can follow
Sending multiple data parameters with jQuery AJAX
http://dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx
http://www.mikesdotnetting.com/Article/96/Handling-JSON-Arrays-returned-from-ASP.NET-Web-Services-with-jQuery
Jquery Ajax Posting json to webservice

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

Comments

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.