Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

ajax submit a object and how to get it in code behind C#

$
0
0
$(document).ready(function () {$("#login").click(function () {

                var username = $("#username").val();

                var password = $("#password").val();

                var user = '{ "username":"' + username + '", "password": "' + password + '" }';//这里,就是将数据封装成json
               
                $.ajax({
                    type: "POST",
                    cache: false,
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    url: 'http://localhost:16620/WebForm1.aspx/User2',
                    data: user ,
                    success: function (result) {
                        alert(result.d);

                    },

                    error: function (err) {

                        alert(err.error());

                    }
             
                })
            })
        })
<form id="form1" runat="server"><div><p>username<input type="text" id="username"/></p><p>password<input type="text" id="password" /></p><input type="button" id="login" value="提交"/></div></form>
 [WebMethod(true)]
 public static string User2(string username,string password)  //work well
        {
        }

[WebMethod(true)]
 public static string User2(string json) //don't wrok,how to let this work as a json string. Because,this could prevent the params are too many.
        {
           
        }





Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>