1.普通的html页面获取后端数据,可以通过Ajax向controller层调用接口,获取数据
<script>
function test(){
var adata = {
"id" : 1,
"name" : "老王"
};
var data = JSON.stringify(adata);
$.ajax({
type : "POST",
dataType: "json",//通过GET方式上传请求
contentType : "application/json",//上传内容格式为json结构
data : data, //上传的参数
async: false ,
url : "test", //请求的url。与后端@Request Mapping注解中的值一致。
success : function(data) { //请求成功的回调函数
if (data.code === 0){
alert("成功");
window.location.href = "success";
}
},
error : function(e) { //请求失败的回调函数
console.log(e);
}
});
};
</script>