首页 > Web开发 > 详细

ajax返回值

时间:2017-06-03 23:01:48      阅读:274      评论:0      收藏:0      [点我收藏+]

前端:

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <script src="~/Scripts/jquery-1.8.2.js"></script>
    <script>
        $(function () {
            $("#btn").click(function () {
                $.ajax({
                    url: "/Home/Test",
                    data: {},
                    dataType: "json",
                    success: function (data) {
                        for (var s in data) {
                            $("#txt" + s).val(data[s]);
                        }
                       
                    }
                })
            })
        })
    </script>
</head>

<body>
    <div>
        <input type="text" id="txtName" /><br />
        <input type="text" id="txtPwd" /><br />
        <button id="btn">提交</button>
    </div>
</body>
</html>

  后端:

     public ActionResult Test()
        {
            Student stu = new Student()
            {
                Name="王大",
                Pwd="123456"
            };
           
            return Json(stu, JsonRequestBehavior.AllowGet);
        }

  

ajax返回值

原文:http://www.cnblogs.com/sunice/p/6938754.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!