Ajax方法回调函数中遍历JSON数据类型问题
functionqwe(){varuserid=jq("#userid").val();if(userid!=null){varcar="";varstr="";jq.a...
function qwe() {
var userid = jq("#userid").val();
if (userid != null) {
var car = "";
var str="";
jq.ajax({
"url" : "ShowShoppingCarServlet",
"type" : "post",
async : false,
"data" : "userid=" + userid,
"dataType" : "JSON",
"success" : function(data4) {
for (var m = 0; m < data4.length; m++) {
car += "<li><div class=\"img\"><a href=\"#\"><img src=\"/imgUrl"+data4[m].fileName+"\" width=\"58\" height=\"58\"></a></div><div class=\"name\"><a href=\"#\">"+ data4[m].names+ "</a></div><div class=\"price\"><font color=\"#ff4e00\">¥"+ data4[m].price+ "</font> X"+ data4[m].goodsnum + "</div></li>";
str+="<tr class=\"car_tr\"><td><div class=\"c_s_img\"><img src=\"/imgUrl"+data6[m].fileName+"\" width=\"73\" height=\"73\" /></div> "+data6[m].names+"</td><td align=\"center\">颜色:灰色</td><td align=\"center\"><div class=\"c_num\"><input type=\"button\" value="" onclick=\""+jianUpdate1(jq(this));+"\" class=\"car_btn_1\" /> <input type=\"text\" value=\"1\" name="" class=\"car_ipt\" /> <input type=\"button\" value="" onclick=\""+addUpdate1(jq(this));+"\" class=\"car_btn_2\" /></div></td><td align=\"center\" style=\"color:#ff4e00;\">¥"+data6[m].price+"</td><td align=\"center\">26R</td><td align=\"center\"><a href=\"#\">删除</a> <a href=\"#\">加入收藏</a></td></tr>";
}
}
});
jq("#cars").append(car);
jq("#showcar").append(str);在for循环中有两个car和str空字符串如何在执行for循环的同时为两个空字符串赋值 展开
var userid = jq("#userid").val();
if (userid != null) {
var car = "";
var str="";
jq.ajax({
"url" : "ShowShoppingCarServlet",
"type" : "post",
async : false,
"data" : "userid=" + userid,
"dataType" : "JSON",
"success" : function(data4) {
for (var m = 0; m < data4.length; m++) {
car += "<li><div class=\"img\"><a href=\"#\"><img src=\"/imgUrl"+data4[m].fileName+"\" width=\"58\" height=\"58\"></a></div><div class=\"name\"><a href=\"#\">"+ data4[m].names+ "</a></div><div class=\"price\"><font color=\"#ff4e00\">¥"+ data4[m].price+ "</font> X"+ data4[m].goodsnum + "</div></li>";
str+="<tr class=\"car_tr\"><td><div class=\"c_s_img\"><img src=\"/imgUrl"+data6[m].fileName+"\" width=\"73\" height=\"73\" /></div> "+data6[m].names+"</td><td align=\"center\">颜色:灰色</td><td align=\"center\"><div class=\"c_num\"><input type=\"button\" value="" onclick=\""+jianUpdate1(jq(this));+"\" class=\"car_btn_1\" /> <input type=\"text\" value=\"1\" name="" class=\"car_ipt\" /> <input type=\"button\" value="" onclick=\""+addUpdate1(jq(this));+"\" class=\"car_btn_2\" /></div></td><td align=\"center\" style=\"color:#ff4e00;\">¥"+data6[m].price+"</td><td align=\"center\">26R</td><td align=\"center\"><a href=\"#\">删除</a> <a href=\"#\">加入收藏</a></td></tr>";
}
}
});
jq("#cars").append(car);
jq("#showcar").append(str);在for循环中有两个car和str空字符串如何在执行for循环的同时为两个空字符串赋值 展开
展开全部
if (userid != null) {
jq.ajax({
"url" : "ShowShoppingCarServlet",
"type" : "post",
async : false,
"data" : "userid=" + userid,
"dataType" : "JSON",
"success" : function(data4) {
var car = "";
var str="";
for (var m = 0; m < data4.length; m++) {
car += "<li><div class=\"img\"><a href=\"#\"><img src=\"/imgUrl"+data4[m].fileName+"\" width=\"58\" height=\"58\"></a></div><div class=\"name\"><a href=\"#\">"+ data4[m].names+ "</a></div><div class=\"price\"><font color=\"#ff4e00\">¥"+ data4[m].price+ "</font> X"+ data4[m].goodsnum + "</div></li>";
str+="<tr class=\"car_tr\"><td><div class=\"c_s_img\"><img src=\"/imgUrl"+data6[m].fileName+"\" width=\"73\" height=\"73\" /></div> "+data6[m].names+"</td><td align=\"center\">颜色:灰色</td><td align=\"center\"><div class=\"c_num\"><input type=\"button\" value="" onclick=\""+jianUpdate1(jq(this));+"\" class=\"car_btn_1\" /> <input type=\"text\" value=\"1\" name="" class=\"car_ipt\" /> <input type=\"button\" value="" onclick=\""+addUpdate1(jq(this));+"\" class=\"car_btn_2\" /></div></td><td align=\"center\" style=\"color:#ff4e00;\">¥"+data6[m].price+"</td><td align=\"center\">26R</td><td align=\"center\"><a href=\"#\">删除</a> <a href=\"#\">加入收藏</a></td></tr>";
}
jq("#cars").append(car);
jq("#showcar").append(str);
}
});
jq.ajax({
"url" : "ShowShoppingCarServlet",
"type" : "post",
async : false,
"data" : "userid=" + userid,
"dataType" : "JSON",
"success" : function(data4) {
var car = "";
var str="";
for (var m = 0; m < data4.length; m++) {
car += "<li><div class=\"img\"><a href=\"#\"><img src=\"/imgUrl"+data4[m].fileName+"\" width=\"58\" height=\"58\"></a></div><div class=\"name\"><a href=\"#\">"+ data4[m].names+ "</a></div><div class=\"price\"><font color=\"#ff4e00\">¥"+ data4[m].price+ "</font> X"+ data4[m].goodsnum + "</div></li>";
str+="<tr class=\"car_tr\"><td><div class=\"c_s_img\"><img src=\"/imgUrl"+data6[m].fileName+"\" width=\"73\" height=\"73\" /></div> "+data6[m].names+"</td><td align=\"center\">颜色:灰色</td><td align=\"center\"><div class=\"c_num\"><input type=\"button\" value="" onclick=\""+jianUpdate1(jq(this));+"\" class=\"car_btn_1\" /> <input type=\"text\" value=\"1\" name="" class=\"car_ipt\" /> <input type=\"button\" value="" onclick=\""+addUpdate1(jq(this));+"\" class=\"car_btn_2\" /></div></td><td align=\"center\" style=\"color:#ff4e00;\">¥"+data6[m].price+"</td><td align=\"center\">26R</td><td align=\"center\"><a href=\"#\">删除</a> <a href=\"#\">加入收藏</a></td></tr>";
}
jq("#cars").append(car);
jq("#showcar").append(str);
}
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询