SpringMVC=>Ajax
2021-01-20 14:13
标签:span charset post cal bin map div com springmvc AjaxController Ajax,soscw.com" target="_blank">SpringMVC=>Ajax 标签:span charset post cal bin map div com springmvc 原文地址:https://www.cnblogs.com/m987/p/12901383.html@ page contentType="text/html;charset=UTF-8" language="java" %>
html>
head>
title>Titletitle>
script src="statics/js/jquery-3.5.1.js">script>
script>
function a1() {
$.post({
url: "${pageContext.request.contextPath}/a3",
data:{"name":$("#name").val()},
success:function (data) { //callback 回调函数
if (data.toString()===‘ok‘){
$("#userInfo").css("color","green");
}else{
$("#userInfo").css("color","red");
}
$("#userInfo").html(data);
}
});
}
function a2() {
$.post({
url: "${pageContext.request.contextPath}/a3",
data:{"pwd":$("#pwd").val()},
success:function (data) { //callback 回调函数
if (data.toString()===‘ok‘){
$("#pwdInfo").css("color","green");
}else{
$("#pwdInfo").css("color","red");
}
$("#pwdInfo").html(data);
}
});
}
script>
head>
body>
p>
用户名: input type="text" id="name" onblur="a1()">
span id="userInfo">span>
p>
p>
密码: input type="text" id="pwd" onblur="a2()">
span id="pwdInfo">span>
p>
body>
html>
package com.min.controller;
import com.min.pojp.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@RestController //加上这个会自动返回字符串
public class AjaxController {
@RequestMapping("/t1")
public String test() {
return "hello";
}
@RequestMapping("/a1")
public void a1(String name, HttpServletResponse response) throws IOException {
System.err.println("a1:param=>" + name);
if ("666".equals(name)) {
response.getWriter().print("true");
} else {
response.getWriter().print("false");
}
}
@RequestMapping("/a2")
public List
上一篇:适配器模式C++实现
文章标题:SpringMVC=>Ajax
文章链接:http://soscw.com/index.php/essay/44566.html