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);
     }

  

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。