前台Ajax发送数据给后台
前台发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":"<=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发送数据给后台的更多相关文章
- Django进阶(路由系统、中间件、缓存、Cookie和Session、Ajax发送数据
路由系统 1.每个路由规则对应一个view中的函数 url(r'^index/(\d*)', views.index), url(r'^manage/(?P<name>\w*)/(?P&l ...
- 【spring 注解 错误】使用controller 作为后台给前台ajax交互数据出错
controller作为后台与前台的ajax进行交互,后台的方法处理完成返回一个boolean类型的值,想传给前台用来判断是否执行成功,BUT,问题来了: 严重: Servlet.service() ...
- 登录(ajax提交数据和后台校验)
1.前台ajax数据提交 <form id="login_form" action="" method="POST"> < ...
- $.ajax 提交数据到后台.
//AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML -- (Extensible Markup Language 可扩展标记语言 ...
- AJAX发送参数到后台,前台火狐debug报undefine
后面经过查找:估计是数据并不是Json格式,由于var PATIENT_ID=getIdSelections();其中PATIENT_ID是数组,所以必须转成字符串. $('#table').on(' ...
- jquery ajax 传数据到后台乱码的处理方法
前台页面先对中文进行编码,如下红色字体: function saveCommentTemplate() { $.ajax({ cache : false, type:'get', dataType:' ...
- 用ajax提交数据到后台以便下载,但是不能下载
在js里面,把一段数据通过post提交给后台,经过后台解析处理,把他以输出流写给浏览器.会发现没得下载提示. 个人觉得是ajax不能解析返回的response里面的流. 如果数据比较大,像post过去 ...
- ajax+js数据模板+后台
.net 后台,ajax+js模板引擎的数据填充,制作无刷新分页 js模板用laytpl 待续...
- django_forms组件用ajax发送数据验证注册
forms组件 -forms是什么? 就是一个类,可以校验字段(前台传过来的字段) -怎么用: -校验字段功能: -先写一个类,继承Form from django.shortcuts import ...
随机推荐
- cf 864 F. Cities Excursions
F. Cities Excursions There are n cities in Berland. Some pairs of them are connected with m directed ...
- Codefroces 849 A,B
A. Odds and Ends time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Node测试文章收藏
1.Nodejs实战—测试Node程序 讲解了TDD与BDD,TDD的基本原则,单元测试常用框架及使用,例如assert断言库, chai断言库, should.js断言库,断言库搭配测试框架(m ...
- mysql 中sql 语句查询今天、昨天、近7天、近30天、一个月内、上一月数据
·1.几个小时内的数据 DATE_SUB(NOW(), INTERVAL 5 HOUR) 1 ·2.今天 select * from 表名 where to_days(时间字段名) = to_days ...
- Swift学习笔记(8)--函数
1.定义及调用 func sayHelloAgain(personName: String) -> String { return "Hello again, " + per ...
- CodeForces 321 A - Ciel and Robot
[题目链接]:click here~~ [题目大意]:一个robot 机器人 .能够依据给定的指令行动,给你四种指令,robot初始位置是(0,0).指令一出.robot会反复行动,推断是否能在无限行 ...
- 记真实自己,炫精彩人生---《爱记》app使用体验
真的有款神器吗,能找到合适的Ta,能秀出自己的新生活,能让自己的心情舒爽,有,体验了下.就是爱记.果粉的福利. [爱记]是集心情记录.分享.评价与交流于一体的工具,TA是你心灵休憩的港湾,也是你记忆放 ...
- 关于TabLayout+ViewPager组合实现多页面滑动
转载请注明出处:http://blog.csdn.net/ht_android/article/details/46647711 在android提供的design library中新增了一个控件,叫 ...
- Android照片墙完整版,完美结合 内存方案 LruCache 和 硬盘方案 DiskLruCache
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/34093441 在上一篇文章当中,我们学习了DiskLruCache的概念和基本用法 ...
- css3的新特性选择器-------属性选择器
自己学css的时候比较乱,这次趁着复习把css3的新特性选择器和css2以前不怎么用的选择器做一个总结 <div id="parent"> <p>I'm a ...