zoukankan      html  css  js  c++  java
  • Ajax常用例子 Post 和 Get

    1.

    前台:Post
    $.ajax({ url:
    "@Url.Action("Save", "UserFun")", type: "post", data: { id: id, "LeaderSayExpand": LeaderSayExpand, }, dataType: "json", success: function (d) { if (d.Success) { if (typeof top.frames[1].setLeaderSay === "function") { top.frames[1].setLeaderSay(LeaderSayExpand); } alert("保存成功!"); TopLayerClose(); } else { alert("保存失败!") } } })

    后台:

    [HttpPost]
    public JsonResult SaveLeaderSay()
    {
    var user = (BJCreation.UserSystem.Domain.User)Session[BJCreation.Helper.Utilies.SessionHelper.SESSION_USER];
    BJCreation.Helper.Utilies.ReqMsg result = new BJCreation.Helper.Utilies.ReqMsg();
    try
    {
    var form = ControllerContext.RequestContext.HttpContext.Request.Params;
    var LeaderSay = form["LeaderSayExpand"];
    var id = form["id"];
    IntelligenceNotice temp = new IntelligenceNotice();
    temp = IntelligenceNoticeService.Get(id);
    IntelligenceNotice obj = new IntelligenceNotice();
    temp.LeaderSay = LeaderSay;
    IntelligenceNoticeService.Save(temp);
    result.Success = true;
    }
    catch (Exception ex)
    {
    CreLog.Error(ex);
    result.Success = false;
    }
    return Json(result, JsonRequestBehavior.AllowGet);
    }

     

    2.

    前台:Get
    $.ajax({ url:
    "@Url.Action("GetAttachmentList", "AttachmentFun")?id=" + id, //往后台传参 type: "get", success: function (d) { $.each(d, function (idx, obj) { if (obj.Id != null) { alert(obj.Id); } }); } });
    后台:

    public JsonResult GetAttachmentList(string id,string DataSource) {
    DataSource = string.IsNullOrEmpty(DataSource) ? "1" : DataSource;
    var list = AttachmentService.GetAttachments(id, DataSource);
    if ("2".Equals(DataSource))
    {
    for (int i = 0; i < list.Count; i++)
    {
    list[i].DataSource = DataSource;
    if (list[i].Type != null)
    {
    if (list[i].Type == "1")
    {
    var url = list[i].Url;
    list[i].Url = JqzbWebUrl + "upload_files/" + url;
    }
    else if (list[i].Type == "2" || list[i].Type == "3")
    {
    var url = list[i].Url;
    list[i].Url = JqzbWebUrl + "output/" + url;
    }
    }
    }
    }
    else {
    foreach (var item in list)
    {
    var url = item.Url;
    item.Url = FileWebUrl + url;
    item.DataSource = DataSource;
    }
    }
    return Json(list, JsonRequestBehavior.AllowGet);
    }

     
  • 相关阅读:
    MySQL常用维护管理工具 枫
    sql触发器 枫
    MySQL函数大全 枫
    使用Cscope阅读Linux源码 枫
    ASP.NET文件下载,直接向客户端输出文件 枫
    网站设计数据库集群和数据库垂直分割,水平分割,库表散列 枫
    西点成品分类 枫
    asp函数列表 枫
    [笔记]一道C语言面试题:实现 itoa() 函数
    [笔记]Arduino平台使用US100超声波测距模块的电平模式测距实验
  • 原文地址:https://www.cnblogs.com/tiancaige/p/11454620.html
Copyright © 2011-2022 走看看