版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bestxianfeng163/article/details/84063448
//前端
你好啊 先锋<button id="btnSend">提交</button>
<script>
$("#btnSend").click(function() {
// $("#request-process-patent").html("正在提交数据,请勿关闭当前窗口...");
$.ajax({
type: "POST",
url: "/SpringBoot/user/testJson",
contentType: "application/json; charset=utf-8",//特别重要
data: JSON.stringify(GetJsonData()),
dataType: "json",
success: function (message) {
if (message > 0) {
alert("请求已提交!我们会尽快与您取得联系");
}
},
error: function (message) {
$("#request-process-patent").html("提交数据失败!");
}
});
});
function GetJsonData() {
var json = {
"id": 1,
"username":"xianfeng",
"password": "12346"
};
return json;
}
</script>
特别要注意要设置参数json类型,否则,hout后台接收不到