Failed to load resource: the server responded with a status of 403
Failed to load resource: the server responded with a status of 403 ()personList.html:1 Failed to load http://192.168.0.103/person/getList: Response to preflight request doesn't pass access control ch.
·
Failed to load resource: the server responded with a status of 403 ()
personList.html:1 Failed to load http://192.168.0.103/person/getList:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://127.0.0.1:8020' is therefore not allowed access. The response had HTTP status code 403.
前后端联调时,出现如上的错误,可能是因为contentType指定不恰当或者后端要求数据格式不匹配引起的
-
后端不要求
json格式,但是前端是json格式前端:
$(function(){ $.ajax({ type:"get", url:"http://192.168.0.103/person/getList", dataType:"json", contentType:"application/json;charset=utf-8", success:function(result){ alert(result); } }); });后端:
@RequestMapping(value = "/getList", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public ResultBean getList() { return new ResultBean(getData()); } -
后端要求是
json,前端传的数据是form表单序列化$("#form").serialize()
前端:$(function(){ $.ajax({ type:"post", url:"http://192.168.0.103/person/createByJson", dataType:"json", data:$("#form").serialize(), contentType:"application/json;charset=utf-8", success:function(result){ alert(result); } }); });后端:
@PostMapping(value = "/createByJson", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public ResultBean createByJson(@RequestBody @Validated Person person) { return new ResultBean(person); }
「智能机器人开发者大赛」官方平台,致力于为开发者和参赛选手提供赛事技术指导、行业标准解读及团队实战案例解析;聚焦智能机器人开发全栈技术闭环,助力开发者攻克技术瓶颈,促进软硬件集成、场景应用及商业化落地的深度研讨。 加入智能机器人开发者社区iRobot Developer,与全球极客并肩突破技术边界,定义机器人开发的未来范式!
更多推荐



所有评论(0)