zoukankan      html  css  js  c++  java
  • uploadify ,前端页面获取值,json,ajax

    针对这几月的技术,做一次小总结

    上传控件uploadify

     1    function inexel() {
     2             $("#btnExcel").uploadify({
     3                 'method': 'post',
     4                 'swf': 'js/uploadify/uploadify.swf',
     5                 'successTimeout': 3,  //设置时间
     6                 'debug': false, 
     7                 'auto': true,
     8                 'multi': false,
     9                 'uploader': 'AjaxSource/FileUpLoad.ashx', //加载成后的ashx页面
    10                 'buttonText': '导入', //文本值
    11                 'fileSizeLimit': '4MB', //文件大小
    12                 'width': 40,
    13                 'height': 16,
    14                 'fileTypeDesc': '支持的格式:',
    15                 'fileTypeExts': '*.xls;',  //文本格式
    16                 'formData': { 'OPT': 'Inexenl' },  //参数值
    17                 'onFallback': function () {/*检测FLASH失败调用*/
    18                     alert("您未安装FLASH控件,无法选择文件!请安装FLASH控件后再试。");
    19                 },
    20                 'onUploadStart': function (file) { },
    21                 'onUploadSuccess': function (file, data, response) {
    22                     var f = $.parseJSON(data);
    23                     if (response) {
    24                         if (f.length > 0) {
    25                             readExcel(f); //把加载后的值,读取后,返回页面table
    26                         }
    27                     } else {
    28                         alert("导入失败,请重新选择!");
    29                     }
    30                 }
    31             });
    32         }
    uploadify

    前台获取返回的json值

      //阅读execl文件
            function readExcel(f) {
                var trtd = "";
                var tacout = ($("#tdui").find("tr").length) - 3;
                for (var i = 0; i < f.length; i++) {
                    var na = f[i].names == undefined ? "" : f[i].names; //名字
                    var se = f[i].sexs == undefined ? "" : f[i].sexs; //性别
                    var phn = f[i].phones == undefined ? "" : f[i].phones; //电话
    }
    }

    radio选中

    if (tyw == '小孩') {
    $('#typ_1').attr('checked', true); //年龄阶段
    } else if (tyw == '成人') {
    $('#typ_2').attr('checked', true);
    } else if (tyw == '老人') {
    $('#typ_3').attr('checked', true);
    } else {
    $('#typ_4').attr('checked', true);
    }

    <label><input name="txtkend" type="radio" id="typ_4" value="婴儿" />婴儿</label><label>
    <input name="txtkend" id="typ_1" type="radio" value="小孩" checked="checked" />小孩</label><label><input
    name="txtkend" type="radio" id="typ_2" value="成人" />成人</label>

    其他数据后台返回json

      1  
      2 //确认的字符串是数据库读取的,自己定义
      3 JObject qb = new JObject();
      4             System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
      5 
      6             //客人名单信息 
      7             JArray jakr = new JArray();
      8             JObject joker = new JObject();
      9             int krert = 0;
     10             //团队信息
     11             JArray jatd = new JArray();
     12             JObject jotd = new JObject();
     13             int tds = 0;
     14             if (string.IsNullOrEmpty(xmld) && string.IsNullOrEmpty(xmltd))
     15             {
     16                 joker.Add("orderid", "kr");
     17                 jakr.Add(joker);
     18                 jotd.Add("orderid", "td");
     19                 jatd.Add(jotd);
     20             }
     21             else
     22             {
     23                 if (!string.IsNullOrEmpty(xmlsor.ToString())) //客人名单 
     24                 {
     25                     for (int i = 0; i < xmlsor.Length; i++)
     26                     {
     27                         string kren = "<xmlkr>" + xmlsor[i] + "</xmlkr>";
     28                         doc.LoadXml(kren);//Name节点名称
     29                         XmlNode xn = doc.SelectSingleNode("xmlkr");
     30                         // 得到根节点的所有子节点
     31                         XmlNodeList node = xn.ChildNodes;
     32                         foreach (XmlNode xnd in node)
     33                         {
     34                             XmlElement xe = (XmlElement)xnd;
     35                             if (xe != null)
     36                             {
     37                                 XmlNodeList nods = xe.ChildNodes;
     38                                 krert += nods.Count;
     39                                 if (krert > 0)
     40                                 {
     41                                     foreach (XmlNode ite in nods)
     42                                     {
     43                                         XmlElement xeh = (XmlElement)ite;
     44                                         joker = new JObject();
     45                                         joker.Add("orderid", xeh.GetAttribute("order").ToString());
     46                                         joker.Add("kguestname", ite.SelectSingleNode("guestname").InnerText);
     47                                         joker.Add("ksex", ite.SelectSingleNode("sex").InnerText);
     48                                         joker.Add("kmobile", ite.SelectSingleNode("mobile").InnerText);
     49                                         joker.Add("kpassport", ite.SelectSingleNode("passport").InnerText);
     50                                         joker.Add("kvisa", ite.SelectSingleNode("visa").InnerText);
     51                                         joker.Add("ktypepass", ite.SelectSingleNode("typepass").InnerText);
     52                                         joker.Add("kcountry", ite.SelectSingleNode("country").InnerText);
     53                                         joker.Add("ken", ite.SelectSingleNode("en").InnerText);
     54                                         joker.Add("khit", ite.SelectSingleNode("hit").InnerText);
     55                                         joker.Add("kguestuu", ite.SelectSingleNode("guestuu").InnerText);
     56                                         jakr.Add(joker);
     57                                     }
     58                                 }
     59                             }
     60                             //if (!string.IsNullOrEmpty(xmlsor[0]))
     61                             //{
     62                             //    list = xmlsor.ToList();
     63                             //    list.RemoveAt(0);
     64                             //    xmlsor = list.ToArray();
     65                             //}
     66                         }
     67                     }
     68                 }
     69                 if (!string.IsNullOrEmpty(xmltd))  //客人信息
     70                 {
     71                     doc.LoadXml(xmltd);//Name节点名称
     72                     XmlNode xn = doc.SelectSingleNode("GuestInfo");
     73                     // 得到根节点的所有子节点
     74                     XmlNodeList node = xn.ChildNodes;
     75                     tds = node.Count;
     76                     if (tds > 0)
     77                     {
     78                         foreach (XmlNode xnd in node)
     79                         {
     80                             jotd = new JObject();
     81                             XmlElement xe = (XmlElement)xnd;
     82                             if (xe != null)
     83                             {
     84                                 XmlNodeList nodelist = xe.ChildNodes;
     85                                 jotd.Add("orderid", xe.GetAttribute("order").ToString());
     86                                 jotd.Add("guestname", xnd.SelectSingleNode("guestname").InnerText);
     87                                 jotd.Add("sex", xnd.SelectSingleNode("sex").InnerText);
     88                                 jotd.Add("mobile", xnd.SelectSingleNode("mobile").InnerText);
     89                                 jotd.Add("passport", xnd.SelectSingleNode("passport").InnerText);
     90                                 jotd.Add("visa", xnd.SelectSingleNode("visa").InnerText);
     91                                 jotd.Add("typepass", xnd.SelectSingleNode("typepass").InnerText);
     92                                 jotd.Add("country", xnd.SelectSingleNode("country").InnerText);
     93                                 XmlNodeList elet = xe.GetElementsByTagName("en");
     94                                 if (elet != null && elet.Count > 0)
     95                                 {
     96                                     string en = "";
     97                                     en = xnd.SelectSingleNode("en").InnerText;
     98                                     if (en != null && en.Length > 0)
     99                                     {
    100                                         jotd.Add("en", en);
    101                                     }
    102                                     else
    103                                     {
    104                                         jotd.Add("en", en);
    105                                     }
    106                                 }
    107                                 else
    108                                 {
    109                                     jotd.Add("en", "");
    110                                 }
    111                                 jotd.Add("hit", xnd.SelectSingleNode("hit").InnerText);
    112                                 jotd.Add("guestuu", xnd.SelectSingleNode("guestuu").InnerText);
    113                                 jatd.Add(jotd);
    114                             }
    115                         }
    116                     }
    117                   
    118                 }
    119               
    120             }
    121             int cout = 0;
    122             if (krert != 0 || tds != 0)
    123             {
    124                 //判断客人数组和团队数组的大小。如果客人数组长度大,则添加团队名单,否则,反之
    125                 if (krert > tds)
    126                 {
    127                     cout = krert - tds;
    128                     for (int i = 0; i < cout; i++)
    129                     {
    130                         jotd = new JObject();
    131                         jotd.Add("orderid", "");
    132                         jotd.Add("guestname", "");
    133                         jotd.Add("sex", "");
    134                         jotd.Add("mobile", "");
    135                         jotd.Add("passport", "");
    136                         jotd.Add("visa", "");
    137                         jotd.Add("typepass", "");
    138                         jotd.Add("country", "");
    139                         jotd.Add("en", "");
    140                         jotd.Add("hit", "");
    141                         jotd.Add("guestuu", "");
    142                         jatd.Add(jotd);
    143                     }
    144                 }
    145             }
    146             qb.Add("kers", jakr);
    147             qb.Add("tds", jatd);
    148             ////先读出客人订单,和团队订单,组成两个数组,最后组成obj ,返回前台对象,
    149             ////前台对象获取<订单号。身份证和名字。进行显示>
    150             //Newtonsoft.Json.Linq.JObject oxml = Newtonsoft.Json.Linq.JObject.FromObject(doc);
    151             //xm = oxml.ToString();ClassUU.ClassStrBase.DeleteHTMLCode(xm.ToString());
    152             return qb.ToString();
    View Code

    其他数据前台json

     //数据加载
            function loads() {
                $.ajax({
                    url: "AjaxSource/TeamList.ashx?OPT=lkr&TeamID=" + $("#ted").val(),
                    type: "POST",
                    success: function (r) {
                        var td = $.parseJSON(r);
                        var kres = td.kers;
                        var tdy = td.tds;
                        //                    console.log(kres);
                        //                    console.log(tdy);
                        //                    .orderid != "kr" && d.tds
                        var ge = document.getElementById('tpl-ShopCart').innerHTML;
                        laytpl(ge).render(td, function (html) {
                            document.getElementById('divselect').innerHTML = html;
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) { layer.msg('网络出现错误了!,请刷新重试或者联系管理员'); },
                    complete: function (XMLHttpRequest, textStatus) {
                    }
                });
            }
    View Code

    前台js模板是参照 layer模板

    http://layer.layui.com/

    大家可以去看看这个网址

  • 相关阅读:
    SQL一条语句统计记录总数及各状态数
    火狐登录国际账户
    HTML基础笔记
    增强for、lambda for、stream 遍历List 结束方法 or 跳过循环本次循环
    nginx
    前端问题总结
    Node.js
    Actuator
    ssh免密登录实现及Python实现
    【Mac渗透测试】之SQL注入Demo
  • 原文地址:https://www.cnblogs.com/luoqin520/p/5796041.html
Copyright © 2011-2022 走看看