ajax post请求400、415错误的一种解决方法
2017-09-14 11:23
531 查看
400、415的错误是数据传送格式造成的。我遇到的情况是:后台需要接收一个对象,我开始的写法是:
function entity(buildingId, typeValue,date) {
this.date = date;
this.buildingId = buildingId;
this.typeValue = typeValue;
}
function text(){
ruturnData = new entity(buildingId, typeValue,date);
type : "post",
url : URL,
data : JSON.stringify(ruturnData),
dataType : "json",
contentType :"application/json",
}
type : "post", url : URL, dataType : "json", contentType :"application/json", data:{ date: date, buildingId :buildingId, typeValue : typeValue, }后台报错不是400就是415,反正是一个类型的错误,我把返回的数据封装成一个对象,再把它用JSON.stringify()解析成一个字符串就好了,具体代码如下:
function entity(buildingId, typeValue,date) {
this.date = date;
this.buildingId = buildingId;
this.typeValue = typeValue;
}
function text(){
ruturnData = new entity(buildingId, typeValue,date);
type : "post",
url : URL,
data : JSON.stringify(ruturnData),
dataType : "json",
contentType :"application/json",
}
相关文章推荐
- @RequestBody之后AJAX请求总是报400/415错误的解决办法
- 解决YII提交POST表单出现400错误,以及ajax post请求时出现400问题
- ajax跨域POST时执行OPTIONS请求服务端返回403forbidden的解决方法
- php ajax提交post请求出现数组被截断情况的解决方法
- SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法
- Ajax请求Session超时的解决办法:拦截器 + 封装jquery的post方法
- SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法
- 用HttpWebRequest做POST请求时返回Http 417 错误解决方法
- SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法
- 前后端分离。前端POST请求参数过长,导致400错误解决办法及分析
- Ajax请求Session超时的解决办法:拦截器 + 封装jquery的post方法
- Nginx静态文件响应POST请求 提示405错误的解决方法
- Ajax请求Session超时的解决办法:拦截器 + 封装jquery的post方法
- SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法
- 解决spring mvc中ajax传值所报的错误400 415
- IE6中ajax aborted错误请求中断解决方法
- ajax跨域jsonp并且post请求No 'Access-Control-Allow-Origin'以及执行error时readyState=4同时status=200的解决方法
- Ajax向后台传json格式的数据出现415错误的原因分析及解决方法
- SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法
- Django POST请求 错误 forbidden(403) CSRF verification failed. Request aborted 解决方法