jquery使用post方法传值
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方法传值的更多相关文章
- MVC中使用Ajax提交数据 Jquery Ajax方法传值到action
Jquery Ajax方法传值到action <script type="text/javascript"> $(document).ready(function(){ ...
- jquery的ajax()函数传值中文乱码解决方法介绍
jquery的ajax()函数传值中文乱码解决方法介绍,需要的朋友可以参考下 代码如下: $.ajax({ dataType : ‘json', type : ‘POST', url : ‘http: ...
- jquery的ajax post 方法传值到后台,无法通过HttpServletRequest得到
今天通过$.ajax({type:"post"});和$.post()方法传值到后台,发现servelet通过HttpServletRequest无法获取到值,但通过get方法却可 ...
- 开发portlet中的一些问题记录,portlet:resourceURL用法,portlet中通过processAction方法传值
在portlet页面中引入js或者css,通过c或者s标签 <!--jquery实际放的地方:/MyTask/WebContent/scripts/jquery-1.8.3.min.js--&g ...
- jquery 通过submit()方法 提交表单示例
jquery 通过submit()方法 提交表单示例: 本示例:以用户注册作为例子.使用jquery中的submit()方法实现表单提交. 注:本示例仅提供了对表单的验证,本例只用选用了三个字段作为测 ...
- jquery.on()超级方法
$.on()方法是jquery1.7之后的一个超级方法,将事件绑定和事件委托整合到一个函数中去,支持绑定多个事件,并且可以绑定自定义事件.使用起来很方便. demo传送门 事件委托 首先说一下事件委托 ...
- 重写jquery的ajax方法
//首先备份下jquery的ajax方法 var _ajax=$.ajax; //重写jquery的ajax方法 $.ajax=function(opt){ //备份opt中error和success ...
- jQuery的extend方法
jq中的extend在面试中经常会被问道,今天我总结一个下有关于extend的用法三种进行对比,可能不全,希望大家指点, 用法一: $.extend({}) ,为jQuery类添加方法,可以理解为扩 ...
- jQuery中eq()方法用法实例
本文实例讲述了jQuery中eq()方法用法.分享给大家供大家参考.具体分析如下: 此方法能够获取匹配元素集上的相应位置索引的元素. 匹配元素集上元素的位置索引是从0开始的. 语法结构: 复制代码 代 ...
随机推荐
- 【powerBI】power pivot添加参数表
背景 最近在做应用分析,爬了几个应用市场的排行榜,需要分析前多少名各个品类的app有多少个.数据量不大,excel就能做分析,所以想起来pivot的参数表功能.这个功能还是比较实用的,在这再做个记录, ...
- uva-10716-贪心
题意:输入长度在100内的小写字母的字符串,求把它变成回文字符串的最少交换次数.如果不能变成回文串,输入,Impossible. 解法: 要变成回文字符串,必须满足一个性质,所有的字符出现次数都是偶数 ...
- error C2011: “timespec”:“struct”类型重定义
error C2011: “timespec”:“struct”类型重定义 C++ pthread pthread.h 中的 timespec 和time.h 中的 结构定义重复了 ,同时两个头文件中 ...
- a.每个 HTML 文件里开头都有个<!DOCTYPE>
<!DOCTYPE> 位于文档中最前面的位置,告诉浏览器以哪个HTML版本进行解析. 在 HTML5 中只有一种:<!DOCTYPE html> .
- Python学习笔记_week2_列表、元组、字典、字符串、文件、i编码
一. 列表.元组 names=["A","B","C","D"] print(names) print(names[0] ...
- SPARK快学大数据分析概要
Spark 是一个用来实现快速而通用的集群计算的平台.在速度方面,Spark 扩展了广泛使用的MapReduce 计算模型,而且高效地支持更多计算模式,包括交互式查询和流处理.在处理大规模数据集时,速 ...
- POI 读写大数据量 EXCEL
参考:https://www.cnblogs.com/tootwo2/p/6683143.html
- leetcode540
这道题目的要求,Note: Your solution should run in O(log n) time and O(1) space. 因此应该用二分查找的方式,代码如下: class Sol ...
- 【Source Insight 】之marco学习笔记2
现在我们看先看一个 官方地址https://www.sourceinsight.com/download/macro-files/中的 autoexp.em Automatically expands ...
- UI5-学习篇-6-SAP创建OData服务-RFC
1.创建项目 2.Import RFC接口 3.定义实体名 目标服务器:若连接外部服务器则需SM59配置Destination 选择RFC函数名 4.选择数据源参数 5.设置主键值 6.保存成功 7. ...