1.js代码

<script type="text/javascript">
function addSku(skuId){
var m = $("#m"+skuId).attr("disabled",true).val(); //变暗复选框
var p = $("#p"+skuId).attr("disabled",true).val();
var i = $("#i"+skuId).attr("disabled",true).val();
var l = $("#l"+skuId).attr("disabled",true).val();
var f = $("#f"+skuId).attr("disabled",true).val();
var url = "/sku/add.do";
var params ={"marketPrice" : m,"skuPrice" : p,"stockInventory" : i,"skuUpperLimit" : l,"deliveFee" : f,"id" : skuId};
$.post(url,params,function(data){alert(data.message)},"json");
        //会自动封装js传来的params参数到Sku对象中
} </script>
<form method="post" id="tableForm">
<table cellspacing="1" cellpadding="0" border="0" width="100%" class="pn-ltable">
<thead class="pn-lthead">
<tr>
<th width="20"><input type="checkbox" onclick="Pn.checkbox('ids',this.checked)"/></th>
<th>商品编号</th>
<th>商品颜色</th>
<th>商品尺码</th>
<th>市场价格</th>
<th>销售价格</th>
<th>库 存</th>
<th>购买限制</th>
<th>运 费</th>
<th>是否赠品</th>
<th>操 作</th>
</tr>
</thead>
<tbody class="pn-ltbody">
<c:forEach items="${skuList }" var="entry">
<tr bgcolor="#ffffff" onmouseover="this.bgColor='#eeeeee'" onmouseout="this.bgColor='#ffffff'">
<td><input type="checkbox" name="ids" value="73"/></td>
<td>${entry.id}-${pno}</td>
<td align="center">${entry.color.name}</td>
<td align="center">${entry.size }</td>
<td align="center"><input type="text" id="m${entry.id }" value="${entry.marketPrice }" disabled="disabled" size="10"/></td>
<td align="center"><input type="text" id="p${entry.id }" value="${entry.skuPrice }" disabled="disabled" size="10"/></td>
<td align="center"><input type="text" id="i${entry.id }" value="${entry.stockInventory }" disabled="disabled" size="10"/></td>
<td align="center"><input type="text" id="l${entry.id }" value="${entry.skuUpperLimit }" disabled="disabled" size="10"/></td>
<td align="center"><input type="text" id="f${entry.id }" value="${entry.deliveFee }" disabled="disabled" size="10"/></td>
<td align="center">不是</td>
<td align="center"><a href="javascript:updataSku(${entry.id })" class="pn-opt">修改</a> | <a href="javascript:addSku(${entry.id })" class="pn-opt">保存</a></td>
</tr>
</c:forEach>
</tbody>
</table>

2.controller层

    @RequestMapping(value="/sku/add.do")
public String add(Sku sku,ModelMap model,HttpServletResponse response){
skuService.updateSkuByKey(sku); //会自动封装js传来的params参数到Sku对象中
JSONObject jo = new JSONObject();
jo.put("message","修改成功");
ResponUtils.renderJson(response, jo.toString());
return "redirect:sku/list.do";
}

3.ResponUtils工具类

public class ResponUtils {

      //发送的是Json
public static void renderJson(HttpServletResponse response,String text){
render(response,"application/json;charset=UTF-8",text);
}
//发送xml
public static void renderXml(HttpServletResponse response,String text){
render(response,"text/xml;charset=UTF-8",text);
}
//发送text
public static void renderText(HttpServletResponse response,String text){
render(response,"text/plain;charset=UTF-8",text);
}
public static void render(HttpServletResponse response,String contentType,String text){
response.setContentType(contentType);
try {
response.getWriter().write(text);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

jquery使用post方法传值的更多相关文章

  1. MVC中使用Ajax提交数据 Jquery Ajax方法传值到action

    Jquery Ajax方法传值到action <script type="text/javascript"> $(document).ready(function(){ ...

  2. jquery的ajax()函数传值中文乱码解决方法介绍

    jquery的ajax()函数传值中文乱码解决方法介绍,需要的朋友可以参考下 代码如下: $.ajax({ dataType : ‘json', type : ‘POST', url : ‘http: ...

  3. jquery的ajax post 方法传值到后台,无法通过HttpServletRequest得到

    今天通过$.ajax({type:"post"});和$.post()方法传值到后台,发现servelet通过HttpServletRequest无法获取到值,但通过get方法却可 ...

  4. 开发portlet中的一些问题记录,portlet:resourceURL用法,portlet中通过processAction方法传值

    在portlet页面中引入js或者css,通过c或者s标签 <!--jquery实际放的地方:/MyTask/WebContent/scripts/jquery-1.8.3.min.js--&g ...

  5. jquery 通过submit()方法 提交表单示例

    jquery 通过submit()方法 提交表单示例: 本示例:以用户注册作为例子.使用jquery中的submit()方法实现表单提交. 注:本示例仅提供了对表单的验证,本例只用选用了三个字段作为测 ...

  6. jquery.on()超级方法

    $.on()方法是jquery1.7之后的一个超级方法,将事件绑定和事件委托整合到一个函数中去,支持绑定多个事件,并且可以绑定自定义事件.使用起来很方便. demo传送门 事件委托 首先说一下事件委托 ...

  7. 重写jquery的ajax方法

    //首先备份下jquery的ajax方法 var _ajax=$.ajax; //重写jquery的ajax方法 $.ajax=function(opt){ //备份opt中error和success ...

  8. jQuery的extend方法

    jq中的extend在面试中经常会被问道,今天我总结一个下有关于extend的用法三种进行对比,可能不全,希望大家指点, 用法一: $.extend({})  ,为jQuery类添加方法,可以理解为扩 ...

  9. jQuery中eq()方法用法实例

    本文实例讲述了jQuery中eq()方法用法.分享给大家供大家参考.具体分析如下: 此方法能够获取匹配元素集上的相应位置索引的元素. 匹配元素集上元素的位置索引是从0开始的. 语法结构: 复制代码 代 ...

随机推荐

  1. 前端通过js-xlsx获取Excel完整数据

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. 第三周C++小结

    其实一些经验或者技巧,都是在作业的过程中搜索得到或者自己领悟出来的. 首先是数值变量与字符变量占用的字节数不同,因此可以用sizeof()函数来判断变量所占字节数判断其类型. 然后是空格的ASCII码 ...

  3. uva-565-枚举

    16个披萨配料,选出一种组合满足所有人的需求,当然,如果某个人不喜欢A,结果里不包含A也是满足这个人的.只要答案满足题意既可,答案不唯一,special judge 用位枚举 #include < ...

  4. yarn 日志查看

    1.  yarn 日志列表 yarn application -list 2. impala-shell impala-shell -q 'invalidate metadata' ## impala ...

  5. Dubbo 暴露服务

    1. 引入dubbo依赖 dubbo 依赖 <dependency> <groupId>com.alibaba</groupId> <artifactId&g ...

  6. sql 2014 安装失败

    SQL Server setup failed to modify security permissions on 原因是 上述目录中没有权限,浏览此文件夹试试,有 错误,删除文件夹,无权删除,通过右 ...

  7. BBS-文章详情页、点赞功能

    文章详情页--布局中header和左边区域不变--用到继承 home_site和article_detail只是布局 中心区域 只是右侧不同-----用到继承原理 -------- url # 文章详 ...

  8. SourceTree commit information window消失解决办法

    https://answers.atlassian.com/questions/15282793/sourcetree-how-to-show-commit-information-panel 执行命 ...

  9. redis 哨兵模式 Connection refused

    spring整合redis哨兵,修改了bind ,protected 任然连接拒绝,是因为哨兵的mastername 和spring里面的名称不一致..导致拒绝了...... 哨兵模式配置文件 属性  ...

  10. Oracle 学习总结 - 物理结构

    参考了很多文章,学习自网络 数据库 = 实例(数据库启动时初始的进程和内存结构,进程会作用到对应的内存区域-数据写入器到写入内存缓冲区,日志写入器到日志缓冲区等) + 数据库(物理文件-控制文件,数据 ...