springmvc返回JSON时候ajax走ERROR

a90434957 2018-01-26 04:11:56
如图,如果直接打印是这样子的。


而走ajax 的话 会走error 打印了错误信息是返回 0


代码如图

...全文
372 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
小程序猿之路 2018-01-27
  • 打赏
  • 举报
回复
引用 6 楼 a90434957 的回复:
[quote=引用 5 楼 jiandan217 的回复:] readystatus是0,正确请求回来应该是4,可能是请求没发出去
是的 。找了好久终于发现了 form内button点击提交出发了不想触发的form action后url变更导致了cancel。 我把button移出去不触发form的action就行了。[/quote] 哈哈,解决了就好啊
a90434957 2018-01-26
  • 打赏
  • 举报
回复
引用 5 楼 jiandan217 的回复:
readystatus是0,正确请求回来应该是4,可能是请求没发出去
是的 。找了好久终于发现了 form内button点击提交出发了不想触发的form action后url变更导致了cancel。 我把button移出去不触发form的action就行了。
小程序猿之路 2018-01-26
  • 打赏
  • 举报
回复
readystatus是0,正确请求回来应该是4,可能是请求没发出去
zzm_fengye 2018-01-26
  • 打赏
  • 举报
回复
引用 3 楼 a90434957 的回复:
[quote=引用 1 楼 zzm9876789 的回复:] 后端写的不对吧!我的是: @RequestMapping(value = "selectUser",method = RequestMethod.POST) public Message selectUser(@RequestBody UserCondition userCondition){ return AppUtils.success(userService.selectUser(userCondition)); } @RequestMapping(value = "getUser",method = RequestMethod.POST) public Message getUser(@RequestParam(value = "userId") Integer user){ return AppUtils.success(""); }
后端用的是注释掉的那一段[/quote] 那你用我的例子试试
a90434957 2018-01-26
  • 打赏
  • 举报
回复
引用 1 楼 zzm9876789 的回复:
后端写的不对吧!我的是: @RequestMapping(value = "selectUser",method = RequestMethod.POST) public Message selectUser(@RequestBody UserCondition userCondition){ return AppUtils.success(userService.selectUser(userCondition)); } @RequestMapping(value = "getUser",method = RequestMethod.POST) public Message getUser(@RequestParam(value = "userId") Integer user){ return AppUtils.success(""); }
后端用的是注释掉的那一段
zzm_fengye 2018-01-26
  • 打赏
  • 举报
回复
后端写的不对吧!我的是: @RequestMapping(value = "selectUser",method = RequestMethod.POST) public Message selectUser(@RequestBody UserCondition userCondition){ return AppUtils.success(userService.selectUser(userCondition)); } @RequestMapping(value = "getUser",method = RequestMethod.POST) public Message getUser(@RequestParam(value = "userId") Integer user){ return AppUtils.success(""); }
zzm_fengye 2018-01-26
  • 打赏
  • 举报
回复
js是: var transferData = { "username": username, "password": password }; $.ajax({ type: "post",//数据发送的方式(post 或者 get) url: "/user/userLogin",//要发送的后台地址 //contentType: "application/json;charset=utf-8", data: transferData,//要发送的数据(参数)格式为{'val1':"1","val2":"2"} dataType: "json",//后台处理后返回的数据格式 success: function (message) {//ajax请求成功后触发的方法 var msg = eval(message); if(msg["errNum"] !== 0){ promptMessage(msg["errNum"],"账号或密码不正确!"); }else{ window.location.href = "index"; } }, error: function (msg) { var err_msg = eval(msg); console.log(err_msg); } });

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧