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. javascrpt基础入门

    JavaScript 是一门脚本语言,同HTML语言一样,需要浏览器或者JavaScript解释器,解释执行. 1. 第一个JavaScript程序: <html> <body> ...

  2. PHP + NGINX 控制视频文件播放,并防止文件下载

    最简单的方法是使用NGINX的 internal 功能 server {    listen 80;    server_name www.xxx.com;     location / {      ...

  3. 解决Run As -> Java Application不能运行问题

    转自:https://breakshell.iteye.com/blog/467130 点 Run As -> Java Application 不能运行,报的错误如下: Plug-in org ...

  4. guava 对集合的支持

  5. 深度学习原理与框架-卷积网络细节-三代物体检测算法 1.R-CNN 2.Fast R-CNN 3.Faster R-CNN

    目标检测的选框操作:第一步:找出一些边缘信息,进行图像合并,获得少量的边框信息 1.R-CNN, 第一步:进行图像的选框,对于选出来的框,使用卷积计算其相似度,选择最相似ROI的选框,即最大值抑制RO ...

  6. 重置mysql5.7密码

    其实想要重置 5.7 的密码很简单,就一层窗户纸: 1.修改 /etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1 这一行配置让 mysqld 启动时不 ...

  7. JSONArray 遍历

    JSONArray 遍历   刚遇到一个接接口任务,发现其中返回数据中,是个字符串数组,数组中就是单个json形式的内容,其实应该也可以称这种数据叫做json数组吧,只不过是字符串形式.而我需要的是将 ...

  8. shell脚本运行springboot项目jar包

    #!/bin/bash APP_NAME=AutomationGuide-0.0.1-SNAPSHOT.jar #使用说明,用来提示输入参数 usage() { echo "please e ...

  9. ReentrantLock 学习笔记

    有篇写的很不错的博客:https://blog.csdn.net/aesop_wubo/article/details/7555956    基于JDK1.8 参考着看源码 ,弄清楚lock()和un ...

  10. java 线程状态相关测试

    1. 启动netty server 等待接受客户端连接 package io.netty.example.myTest.nio; import java.io.IOException; import ...