基于SpringMVC的Ajax
来源:互联网 发布:matlab 无标度网络 编辑:程序博客网 时间:2024/05/16 08:31
后台代码
package controller;import javax.servlet.http.HttpServletRequest;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;@Controllerpublic class AjaxHandler {@RequestMapping(value = "/ajax.action", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")@ResponseBodypublic String method1(HttpServletRequest request) {// 获得key为username的valueString username = request.getParameter("username");// 处理获得的参数System.out.println(username);String reslut = "登录成功:" + username;// 返回结果return reslut;}}
前台代码
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script> <script type="text/javascript"> $(function() { /* Ajax post */ $('#submitbt').click(function() { var Username = $("#username").val(); $.post("ajax.action", { username : Username, }, function(data) { //从后台传过来的数据 alert(data); }); }); /* Ajax post */ }); </script> <body> <form action="" method="post"> username<input type="text" name="username" id="username" /> <input type="button" value="Ajax" id="submitbt"> </form> </body>
阅读全文
1 0
- 基于SpringMVC的Ajax
- 基于spring3.0的springmvc的ajax数据请求
- SpringMVC的AJAX返回
- springMVC的ajax请求
- springmvc ajax的支持
- SpringMvc的ajax
- ajax无刷新上传图片,基于springMVC
- 基于springMvc ajax返回中文乱码
- 基于注解的SpringMVC
- 基于注解的springmvc
- 基于注解的springmvc
- 基于注解的SpringMVC
- 基于注解的SpringMVC
- 基于注解的SpringMVC
- 基于xml的SpringMVC
- 基于注解的SpringMVC
- 基于注解的SpringMVC
- 基于注解的SpringMVC
- postgres drop table后会删除物理文件
- if语句与流程控制语句
- leveldb:VersionSet
- 【洛谷2243】电路维修
- TCP 客户端
- 基于SpringMVC的Ajax
- js阻止默认行为
- HDU
- 应对分布式缓存宕机的方案
- HGDB与oracle中dual的区别
- Java设计模式整理
- Java深(Deep)拷贝与浅(Shadow)拷贝
- 百度地图调用实例
- 算法day06