$.ajax与$.post、$.get的一点区别

后台代码:
[HttpPost]
        public string DoLogin(string username,string password)
        {
            return "success";
        }

当使用$.ajax时:

var name = $('#txtUserName').val();
                var pwd = $('#txtPassWord').val();
                var param = "{username:'" + name + "',password:'" + pwd + "'}";
                $.ajax({
                    type: "POST",
                    url: "/Main/DoLogin",
                    data: param,
                    contentType: "application/json;charset=utf-8",
                    success: function (msg)
                    {
                        var test = msg;
                        var test2 = test;
                    },
                    error: function (e)
                    {
                        var test = e;
                        var test2 = test;
                    }
                });

当使用$.post时:

var name = $('#txtUserName').val();
                var pwd = $('#txtPassWord').val();
                var param = { username: name, password: pwd };
                $.post('/Main/DoLogin', param, function (result) {
                    var test = result;
                    alert(test);
                },'json');

 

posted @ 2018-05-29 14:34  cl94  阅读(120)  评论(0编辑  收藏  举报