• MVC + JQUERY + AJAX


    .aspx页面

    <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
        主页
    </asp:Content>

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript" src="../../Scripts/jquery-1.4.1.min.js"></script>

       <div>
       <input type="button" id="button1" value="提交" onclick="on_Click();" />
         <ul id="ul_li"></ul>
       </div>

     <script type="text/javascript">
         $(function () {
             $.ajax({
                 type: "post",
                 data: "",
                 async: true, //异步
                 url: '<%=Url.Action("gClass","Home") %>',
                 cache: false, //不加载缓存
                 success: function (result) {
                     var jsonResult = result;
                     for (var json in jsonResult) {
                         $("#ul_li").append($("<li>" + jsonResult[json].Name + "|||" + jsonResult[json].ID + "</li>"));
                     }
                 },
                 error: function () {
                     alert("请求失败");
                 }
             })
             // })
         })
      </script>
    </asp:Content>

    Controllers层

    public JsonResult gClass()
            {
                List<ClassInfo> list = SqlConn.cList();
                return Json(list);
            }

    数据层

    public static List<ClassInfo> cList()
            {
                List<ClassInfo> list = new List<ClassInfo>();
                ClassInfo cinfo;
                for (int i = 0; i < 10; i++)
                {
                    cinfo = new ClassInfo();
                    cinfo.ID = i;
                    cinfo.Name = "UserName" + i;
                    cinfo.set = true;
                    cinfo.Address = "北京市" + i;
                    list.Add(cinfo);
                }
                return list;
            }

  • 相关阅读:
    php 本地 备份远程mysql和mdb 多任务只执行一次
    c# 监控服务器上传木马(包含可疑文件)
    jquery 简短 右键菜单 兼容ie6 ie7 ie8 firefox chrome
    分解从身份证中读回的户籍地址
    备份mysql(一表一文件)
    THINKPHP 3.0 整合KINDEDITOR 4.05
    c# 仿照计划任务(定时提示、定时运行程序、定时打开url(前台/后台))/每天/每周/每月/一次 多时间段
    php基本操作echo
    c# 扫描可疑文件(找到木马)(简)
    GOOGLE 地图,查询地名,移动标记,生成静态地图
  • 原文地址:https://www.cnblogs.com/zhaoliang831214/p/3485088.html
Copyright © 2020-2023  润新知