本来想用ajax返回控制器返回的字符串,但是一直返回另一个页面的整个html代码,检查了好久突然想起来我配了springboot的拦截器,将我的ajax请求拦截并返回了一个页面,让这个请求通过即可
function support(){
let message = [[${topic.id}]]
let count = [[${topic.getSupportCount()}]]
$.get({
url: "/chen/topic/supportOrCriticism/" + message + "/1",
success: function (data){
if (data === "success"){
$("#support").css("color", "deeppink");
$("#support").html(count + 1);
}
if (data === "error"){
layer.msg("data")
}
},
error: function (){
alert("失败")
}
})
}
原因是配置了springboot拦截器,
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginHandlerInterceptor())
.addPathPatterns("/**").excludePathPatterns("/css/**");
}