Jquery ajax异步提交
2023-09-14 09:00:23 时间
$.ajax({
url: /project/studentRpc/ +studentid+ /deleteStudentById.json ,
t
$.ajax({ url:"/project/studentRpc/"+studentid+"/deleteStudentById.json", type:"get", dataType: json, success:function(data){ var isDeleted= data.content.successed; alert(typeof isDeleted); if(isDeleted==true){ alert("删除成功"); window.location.reload(); } } }); } /script
$.ajax({ url:"/project/studentRpc/"+studentid+"/deleteStudentById.json", type:"get", dataType: json, success:function(data){ var isDeleted= data.content.successed; alert(typeof isDeleted); if(isDeleted==true){ alert("删除成功"); window.location.reload(); } } }); } /script
dataType:json 设置返回值类型
contentType:"application/x-www-form-urlencoded"(默认值)
contentType参考文章:
http://blog.csdn.net/mhmyqn/article/details/25561535
页面采用回调函数function(data) 处理后台返回的结果
a标签onclick事件触发
a href ="javascript:void(0);" id ="add" onclick = "return addproduct(${s.id});" 加入秒杀 /a
前台
function addproduct(id){ var mprice=document.getElementById("mprice_"+id).value; var number=document.getElementById("number_"+id).value; var sid=document.getElementById("special.id").value; if (mprice==""){ alert("请输入特价价格"); return false; }else if (number==""){ alert("请输入特价数量 "); return false; }else { //重点在这儿 $.get("${ctx}/special/addProduct.action?specialVo.quantity="+number+" specialVo.memberPrice="+mprice+" specialVo.id="+id+" special.id="+sid, function(data){ if(data=="true"){ alert("添加成功"); window.location.reload(); /* window.location.href="${ctx}/special/addProduct.action?specialVo.quantity="+number+" specialVo.memberPrice="+mprice+" specialVo.id="+id+" special.id="+sid; */ }
后台
public void addProduct(){ PrintWriter out=null; try { System.out.println(specialVo.getQuantity()); System.out.println(specialVo.getMemberPrice()); System.out.println(specialVo.getId()); System.out.println(special.getId()); HttpServletResponse response=ServletActionContext.getResponse(); out=response.getWriter(); out.print(true); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); out.flush(); out.close(); out.println(0); }
struts配置action无需result
action name="addProduct" method="addProduct" /action
方法有两种,一是返回无类型,即void类型,二是返回Action.NONE(String类型)当是这两种类型的时候,struts2就不会对result进行主动处理了
即我们只需要在action方法中,处理ajax调用,而返回void或者"none"就行了
参考文章:
http://bbs.csdn.net/topics/390470284
http://blog.csdn.net/xuzhuang2008/article/details/6928304
本文出自 “点滴积累” 博客,请务必保留此出处http://tianxingzhe.blog.51cto.com/3390077/1678174
相关文章
- ajax cors跨域_jquery跨域
- 什么是Ajax以及ajax请求的步骤[通俗易懂]
- Jquery Ajax 跨域调用asmx类型 WebService范例
- jQuery
- jquery validation engine ajax验证,jQuery Validation Engine 表单验证「建议收藏」
- jQuery表单插件jquery.form.js详解编程语言
- Jquery中的.post和 .ajax两个方法的区别是什么详解编程语言
- jQuery contextmenu事件详解
- Ajax实现从MySQL读取数据(ajax 读取mysql)
- 使用jQuery简化Ajax开发
- 限制字符输入数功能(jquery版和原生JS版)
- jquery全局AJAX事件使用代码
- Jquery工作常用实例使用AJAX使网页进行异步更新
- jQuery使用动态渲染表单功能完成ajax文件下载
- 用原生JavaScript实现jQuery的$.getJSON的解决方法
- Jquery实现视频播放页面的关灯开灯效果
- Jquery通过Ajax方式来提交Form表单的具体实现
- 写JQuery插件的基本知识
- jQuery中使用Ajax获取JSON格式数据示例代码
- Jquery使用FirefoxFireBug插件调试Ajax步骤讲解
- 探讨jQuery的ajax使用场景(c#)
- 解析jQuery的三种bind/One/Live事件绑定使用方法
- asp.net中利用Jquery+Ajax+Json实现无刷新分页的实例代码
- jQuery判断元素是否存在的可靠方法
- jquery的ajax异步请求接收返回json数据实例
- jquery+php+ajax显示上传进度的多图片上传并生成缩略图代码
- jquery.ajax之beforeSend方法使用介绍
- JQuery中使用Ajax赋值给全局变量失败异常的解决方法