今天写注册登录界面,需要从后台获取数据,代码如下:
http://localhost:3000/regist以上是注册界面的地址
url:"http://127.0.0.1:3000/api/regist",以上为ajax的url,原来以为localhost和127.0.0.1是一个地址,结果一直报错
Failed to load http://127.0.0.1:3000/api/regist?user=123%401&psw=111111: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.把ajax的url换成 url:"http://localhost:3000/api/regist",
就不会报错了
本文记录了在开发过程中遇到的一个关于跨域的问题,并分享了解决方案。作者在进行注册登录界面开发时,尝试从后台获取数据,发现使用127.0.0.1作为请求地址时出现跨域错误。通过将请求地址更改为localhost,成功解决了该问题。
3266

被折叠的 条评论
为什么被折叠?



