• js 利用ajax将前台数据传到后台(1)


    不是json格式的.

     1       $.ajax({
     2                 type: "Post",
     3                 url: "/activity/AuditAdd",
     4                 data: { UserName: $('#userName').val(), UserCertId: $('#userCertId').val(), BankInfo: $("#province_AreaCode").find("option:selected").text() + $("#city_AreaCode").find("option:selected").text() + $('#bankName').val() + $('#subbranchName').val(), CardID: $('#confirm').val(), Phone: $('#phone').val(), Email: $('#email').val() },
     5                 dataType: "json",
     6                 success: function (r) {
     7                     if (r.success == true) {
     8                         $('#submitMsg').show();
     9                         $('#application').hide();
    10                         $(":text").val("");
    11                     } else {
    12                         alert("存在相同的身份证号码");
    13                         return false;
    14                     }
    15 
    16                 },
    17                 error: function (err) {
    18                     alert("提交失败");
    19                 }
    20             });

    不管那么多了,这是工作上的代码.

    其中 url是方法的地址

    data是要传过去的数据

    再好像..没什么需要解释的了

    贴下后台代码(mvc4):

     1 public ActionResult AuditAdd(Product_ActivityUsers model, string UserName, string UserCertId, string BankInfo, string CardID, string Phone, string Email, string Province, string City)
     2         {
     3             model.ID = IdentityCreator.NextIdentity;
     4             model.ContactName = UserName;
     5             model.UserCertId = UserCertId;
     6             model.UserBankCardId = CardID;
     7             model.ContactPhone = Phone;
     8             model.ContactEmail = Email;
     9             model.IsAvailable = 0;
    10             model.IsDel = 0;
    11             model.AddDate = DateTime.Now;
    12             model.IsSync = 0;
    13             string str = BankInfo;
    14             StringBuilder sb = new StringBuilder(str);
    15             sb.Replace("请选择城市", "");
    16             model.UserBankInfo = sb.ToString().Trim();
    17             if (!o_Res.IsExistProduct_ActivityUsersByCertId(UserCertId))
    18             {
    19                 if (o_Res.CreateProduct_ActivityUsers(model))
    20                 {
    21                     return Json(new MLJsonResult { msg = Resources.Message.SaveSuccess, success = true });
    22                 }
    23             }
    24             return Json(new MLJsonResult { msg = Resources.Message.SaveFailure, success = false });
    25         }

    也没什么刻意需要解释的,以后看见这些代码就知道是什么意思了.

  • 相关阅读:
    284. Peeking Iterator 光是看看下一个值的遍历
    339. Nested List Weight Sum 339.嵌套列表权重总和
    341. Flatten Nested List Iterator展开多层数组
    springcloud之配置中心服务化和高可用
    springcloud之配置中心git
    springcloud之熔断监控Hystrix Dashboard和Turbine
    springcloud之熔断器Hystrix
    springcloud之服务提供与调用
    springcloud之注册中心Eureka
    springcloud之大话springcloud
  • 原文地址:https://www.cnblogs.com/hiytom/p/3277729.html
Copyright © 2020-2023  润新知