码迷,mamicode.com
首页 > Web开发 > 详细

ajax返回值

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

标签:title   text   name   pre   for   idt   click   txt   highlight   

前端:

<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返回值

标签:title   text   name   pre   for   idt   click   txt   highlight   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!