前台发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));
}

前台Ajax发送数据给后台的更多相关文章

  1. Django进阶(路由系统、中间件、缓存、Cookie和Session、Ajax发送数据

    路由系统 1.每个路由规则对应一个view中的函数 url(r'^index/(\d*)', views.index), url(r'^manage/(?P<name>\w*)/(?P&l ...

  2. 【spring 注解 错误】使用controller 作为后台给前台ajax交互数据出错

    controller作为后台与前台的ajax进行交互,后台的方法处理完成返回一个boolean类型的值,想传给前台用来判断是否执行成功,BUT,问题来了: 严重: Servlet.service() ...

  3. 登录(ajax提交数据和后台校验)

    1.前台ajax数据提交 <form id="login_form" action="" method="POST"> < ...

  4. $.ajax 提交数据到后台.

    //AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML -- (Extensible Markup Language 可扩展标记语言 ...

  5. AJAX发送参数到后台,前台火狐debug报undefine

    后面经过查找:估计是数据并不是Json格式,由于var PATIENT_ID=getIdSelections();其中PATIENT_ID是数组,所以必须转成字符串. $('#table').on(' ...

  6. jquery ajax 传数据到后台乱码的处理方法

    前台页面先对中文进行编码,如下红色字体: function saveCommentTemplate() { $.ajax({ cache : false, type:'get', dataType:' ...

  7. 用ajax提交数据到后台以便下载,但是不能下载

    在js里面,把一段数据通过post提交给后台,经过后台解析处理,把他以输出流写给浏览器.会发现没得下载提示. 个人觉得是ajax不能解析返回的response里面的流. 如果数据比较大,像post过去 ...

  8. ajax+js数据模板+后台

    .net 后台,ajax+js模板引擎的数据填充,制作无刷新分页 js模板用laytpl 待续...

  9. django_forms组件用ajax发送数据验证注册

    forms组件 -forms是什么? 就是一个类,可以校验字段(前台传过来的字段) -怎么用: -校验字段功能: -先写一个类,继承Form from django.shortcuts import ...

随机推荐

  1. 安装oracle常见问题分析

    1,之前已经安装过软件,卸载不完全 /tmp/.oracle /tmp/ora* /var/tmp/ora* /etc/ora* 2,安装介质权限或者本身就有问题 3,oracle用户 $/HOME/ ...

  2. SQL保存XML报错 “XML 分析: 行 1,字符 47,非法的 xml 字符”

    例如: <?xml version="1.0" encoding="utf-8" standalone="yes"?> < ...

  3. CCF模拟题 字符串匹配

    字符串匹配 时间限制: 1.0s 内存限制: 256.0MB 问题描述 给出一个字符串和多行文字,在这些文字中找到字符串出现的那些行.你的程序还需支持大小写敏感选项:当选项打开时,表示同一个字母的大写 ...

  4. 洛谷 P2684 搞清洁

    P2684 搞清洁 题目描述 FJ准备分配它的N只奶牛(1 <= N <= 25,000) 做清洁工作,他把一天分成T(1 <= T <= 1,000,000)个时间段,他希望 ...

  5. 洛谷 P3130 [USACO15DEC]计数haybalesCounting Haybales

    P3130 [USACO15DEC]计数haybalesCounting Haybales 题目描述 Farmer John is trying to hire contractors to help ...

  6. 【VC编程技巧】窗口☞3.4利用bitmap改变对话框的背景。

    效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hlbl9qaW50/font/5a6L5L2T/fontsize/400/fill/I0JBQ ...

  7. hdu 1875 畅通project再续(kruskal算法计算最小生成树)

    畅通project再续 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  8. JavaScript中获取Map集合中的key和value值(前提是:既不知道key为什么值,也不知道value有哪些值)

    for(var i in maps){//通过定义一个局部变量i遍历获取map里面的所有key值 alert(maps[i]); //通过获取key对应的value值 }

  9. webgoat 7.1 实战指南

    WSASP中文文档参考链接: http://www.owasp.org.cn/owasp-project/2017-owasp-top-10 OWASP Top 10 2017中文版V1.3http: ...

  10. WebGoat学习(一)--环境搭建

    参考https://www.owasp.org/index.php/Category:OWASP_WebGoat_Project https://github.com/WebGoat/WebGoat ...