• js以json形式提交数据,后台接受


    $("#savename").click(function(){
        var fananname=$("#editname").val();
        var jsonList = eval(createArray()); 
        var jsonText = JSON.stringify(jsonList);
        $.ajax({
            type: "POST",
            url: "/shop/ffselect!saveAttachedUrl.action",
            dataType:"json",
            data: {
                "fanan":fananname,
                "jsonarray":jsonText
            },
                success: function(data) {
                if(data.status=="success"){
                    window.location.href="www.baidu.com";
                }
                },
        });    
        
    })
    
    function createArray(){
        var jsonarray=[];
        var fanganid=$("#selectTitleid").val();
        var $goodsurl=$(".goodsurl");
        var $isadd=$(".isadd");
        var $review=$(".inputtextarea");
        var $isclear=$(".isclear");
        
        $.each($goodsurl,function(n){
            var goodsurl=$($goodsurl[n]).val();
            var isadd=$($isadd[n]).val();    
            var review=$($review[n]).val();
            var isclear=$($isclear[n]).val();
            var obj=createObj(goodsurl,isadd,fanganid,review,isclear);
            jsonarray.push(obj);
        })
        return jsonarray;
    }
    
    function createObj(urlval,isaddval,faidval,reviewval,isclearval){
        return {
            url:urlval,
            isadd:isaddval,
            faid:faidval,
            review:reviewval,
            isclear:isclearval
        }
    }
    

      后台接收

     public String saveAttachedUrl(){
            LlSelectAttachedUrl attacheURL = new LlSelectAttachedUrl();
             String fanan = getParameter("fanan");
             String jsonarray = getParameter("jsonarray");
             System.out.println(fanan);
             System.out.println(jsonarray);
     //        String str = "[{'name':'张三','sex':'男'},{'name':'李四','sex':'女'},{'name':'王五','sex':'男'}]";
             JSONArray json = JSONArray.fromObject(jsonarray);
             int size = json.size();
            for(int i = 0; i<size; i++){
                 String re = json.getString(i);
                 JSONObject s = JSONObject.fromObject(re);
                 attacheURL.setAdd_date(new Date());
                 attacheURL.setComments(s.getString(""));
                 attacheURL.setGoods_url(s.getString(""));
                 attacheURL.setId(re);
                 attacheURL.setRemark(s.getString(""));
                 attacheURL.setSelect_title_id(s.getString(""));
                 if(s.getString("")!=null){
                     attacheURL.setIsAddUrl(Integer.parseInt(s.getString("")));
                 }if(s.getString("")!=null){
                     attacheURL.setState(Integer.parseInt(s.getString("")));
                 }
                 this.selectFanFan.saveSelectAttachedUrl(attacheURL);
             }
             return ajax(Status.success);
         }
    

      

  • 相关阅读:
    解读Android 12首个开发者预览版
    Pod创建私有库
    Flutter常用网站
    Flutter常用快捷键
    多个网络请求-并发执行、顺序执行
    小猫爬山问题---贪心算法失效,深度优先搜索优化
    网络基本概念备忘:MAC地址,端口,HTTP状态码
    常见图片文件格式简析
    pdf2xls
    评分卡模型
  • 原文地址:https://www.cnblogs.com/kt520/p/4450015.html
Copyright © 2020-2023  润新知