$("#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
}
}
后台接受 1 public String saveAttachedUrl(){
2 LlSelectAttachedUrl attacheURL = new LlSelectAttachedUrl();
3 String fanan = getParameter("fanan");
4 String jsonarray = getParameter("jsonarray");
5 System.out.println(fanan);
6 System.out.println(jsonarray);
7 // String str = "[{'name':'张三','sex':'男'},{'name':'李四','sex':'女'},{'name':'王五','sex':'男'}]";
8 JSONArray json = JSONArray.fromObject(jsonarray);
9 int size = json.size();
10 for(int i = 0; i<size; i++){
11 String re = json.getString(i);
12 JSONObject s = JSONObject.fromObject(re);
13 attacheURL.setAdd_date(new Date());
14 attacheURL.setComments(s.getString(""));
15 attacheURL.setGoods_url(s.getString(""));
16 attacheURL.setId(re);
17 attacheURL.setRemark(s.getString(""));
18 attacheURL.setSelect_title_id(s.getString(""));
19 if(s.getString("")!=null){
20 attacheURL.setIsAddUrl(Integer.parseInt(s.getString("")));
21 }if(s.getString("")!=null){
22 attacheURL.setState(Integer.parseInt(s.getString("")));
23 }
24 this.selectFanFan.saveSelectAttachedUrl(attacheURL);
25 }
26 return ajax(Status.success);
27 }