前台发ajax请求给后台

前台代码

let data= [{receiveAdd:receiveAddVal, sendAdd:sendAddVal,distance:distance,goodsName:goodsName,editname:editname,weight:weight,editnotename:editnotename,dataTime:dataTime,receiveName:receiveName,receiveSex:receiveSex,receiveTel:receiveTel,sendName:sendName,sendSex:sendSex,sendTel:sendTel,price:price}]
this.$ajax({
method: 'post',
url: 'http://192.168.31.248:8080/sd_tech/PlaceOrder.do',
dataType:'json',
data:{
dataDetail: JSON.stringify(data)
}
}).then(response=>{
alert('post code done')
this.$router.push({path:'/pay'})
}).catch(function(err){
console.log(err)
});

也可以这样发送Ajax:

 let data= [{receiveAdd:receiveAddVal, sendAdd:sendAddVal,distance:distance,goodsName:goodsName,editname:editname,weight:weight,editnotename:editnotename,dataTime:dataTime,receiveName:receiveName,receiveSex:receiveSex,receiveTel:receiveTel,sendName:sendName,sendSex:sendSex,sendTel:sendTel,price:price}]
this.$ajax({
method: 'post',
url: 'http://192.168.31.248:8080/sd_tech/PlaceOrder.do',
dataType:'json',
data:{
dataDetail: JSON.stringify(data)
},
success:function (response) {
alert('post code done')
this.$router.push({path:'/pay'})
},
error:function (err) {
console.log(err)
}
})

后台代码:

    @RequestMapping(value="PlaceOrder.do",produces="application/json;charset=utf-8")
@ResponseBody
public String PlaceOrder(@RequestBody Map<String,String> params, HttpServletRequest request,HttpServletResponse response,
SdOrder sdOrder,String orderStartPoint)/* throws UnsupportedEncodingException*/{
//前端接收到的json串
/*dataDetail : [{"receiveAdd":"北京市通州区番茄俱乐部","sendAdd":"北京市通州区恺王国际","distance":9.463,
"goodsName":"生活用品","editname":"11","weight":"&lt;=5kg","editnotename":"11",
"dataTime":["今天","上午","1点","20分"],"receiveName":"哈哈","receiveSex":"男",
"receiveTel":"13633633666","sendName":"嘿嘿","sendSex":"男","sendTel":"15655655666","price":"28元"}]*/
System.out.println("总共获取到:"+params.size()+"个参数");
for(String key : params.keySet()){
System.out.println(key + " : " + params.get(key));
}
05-22 05:13