62 jQuery-使用全局函数post()向服务器请求数据

版权声明:本文为大都督作者的原创文章,未经 大都督 允许也可以转载,但请注明出处,谢谢! 共勉! https://blog.csdn.net/qq_37335220/article/details/85848801

1.效果图

在这里插入图片描述

2.HTML代码

2.1 jquery_post.html页面代码

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <title>62 jQuery-使用全局函数post()向服务器请求数据</title>
    <style type="text/css">
           body{font-size:13px}
           .divFrame{width:260px;border:solid 1px #666}
           .divFrame .divTitle{padding:5px;background-color:#eee;}
           .divFrame .divContent{padding:8px}
           .divFrame .divContent .clsShow{font-size:14px}
           .btn {border:#666 1px solid;padding:2px;width:80px;
           filter: progid:DXImageTransform.Microsoft
           .Gradient(GradientType=0,StartColorStr=#ffffff,
           EndColorStr=#ECE9D8);}
    </style>
</head>
<body>
	<div class="divFrame">
         <div class="divTitle">
         	  姓名:<input type="text" id="name" style="width: 120px;">
              <input id="Button1" type="button" class="btn" value="获取数据" />
         </div>
         <div class="divContent">
              <div id="divTip"></div>
         </div>
     </div>
<script src="../../js/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
	//按钮点击事件
	$("#Button1").click(function(){
		//打开文件,并通过回调函数处理获取的数据
		$.post("/jquery/userInfo_html", {name:$("#name").val()}, function(data){
			//先清空标记中的内容,再显示服务器返回的数据
			$("#divTip").empty().html(data);
		})
	})
})
</script>
</body>
</html>

2.2 jquery_post.html页面代码

您输入的姓名是:${uName!}

3.Java代码

package com.example.demo.manager;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Description jquery控制层
 * @author 大都督
 * @date 2019年1月3日
 */
@Controller
@RequestMapping("/jquery")
public class JqueryManager extends BaseManager{

	/**
	 * 
	* @Title: userInfo_html 
	* @Description:获取userInfo.html页面 
	* @return 
	* @author 大都督
	* @date 2019年1月5日
	* @return String
	 */
	@PostMapping("/userInfo_html")
	public String userInfo_html(String name, Map<String, Object> map) {
		map.put("uName", name);
		System.out.println("uName=============="+name);
		return "jquery/testFile/userInfo.html";
	}
	/**
	 * 
	 * @Title: jquery_post 
	 * @Description:跳转到jquery_post页面  
	 * @return 
	 * @author 大都督
	 * @date 2019年1月5日
	 * @return String
	 */
	@RequestMapping("/jquery_post")
	public String jqueryPost() {
		return "jquery/ajax/jquery_post";
	}
}

猜你喜欢

转载自blog.csdn.net/qq_37335220/article/details/85848801
62
62-