SSH实现ajax
2024-09-12 11:43:50
(1)首先要引入需要pom文件
<!-- https://mvnrepository.com/artifact/org.apache.struts/struts2-json-plugin -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>2.3.16.3</version>
</dependency>
(2)需要的数据,返回什么类型的都可以
private List<Integer> list; //要返回前台的值 list集合
private Integer productId; //前台获取的值 public Object totalQuantity() {
System.out.println(productId);
list = productService.findByID(productId);
System.out.println(list);
return "ajax";
} //省略getter和setter方法
(3)配置action
result节点中的name:返回的值 type:返回序列化的格式
root:要序列化的对象 默认将序列化当前Action中所有有返回值的getter方法的值
===list( 要返回页面的数据 在action要有getter方法)
<action name="totalQuantity" class="cn.ssh.action.ProductAction" method="totalQuantity">
<result name="ajax" type="json" >
<param name="root">list</param>
</result>
</action>
(4)前台ajax
$.ajax({
url:"/totalQuantity.action", //访问action的路径
type:"POST",
data:{
//传递到后台的值
},
dataType:"JSON",
success:function (data) {
//成功操作
$.each(data, function (i, dom) { });
} })
最新文章
- POJ 2225 / ZOJ 1438 / UVA 1438 Asteroids --三维凸包,求多面体重心
- ubuntu一些常用的命令
- grep(Global Regular Expression Print)
- .NET 分页
- 记录一下,关于错误提示:could not find a part of path “X:\”的解决办法
- Spring factorybean
- spring整合mybatis错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist
- 转:【Java并发编程】之一:可重入内置锁
- ABP官方文档翻译 4.4 授权
- 在Coding上搭建Hexo个人博客
- CSS3常用
- python 读取excel文件
- 搭建opencv javaweb项目
- arcgis 获得工具箱工具的个数
- python练习题-day9
- MySQL数据库的库表基本操作
- 玩转 React 【第03期】:邂逅 React 组件
- Go语言编程 (许式伟 等 著)
- matlab 画图参考小程序
- 复选框、单选框 jquery判断是否选中Demo