localhost和127.0.0.1不同源

今天写注册登录界面,需要从后台获取数据,代码如下:
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",

就不会报错了

猜你喜欢

转载自blog.csdn.net/kangzai2012/article/details/80955220