AJAX跨越、JS跨越请求 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin
2017-11-19 20:37
666 查看
报错:XMLHttpRequest cannot load http://localhost:8081/category.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8082' is therefore not allowed access.
什么是跨域:
1、Js是不能跨域请求。出于安全考虑,js设计时不可以跨域。
2、域名不同时。
3、域名相同,端口不同。
3、只有域名相同、端口相同时,才可以访问。
二、解决跨越问题
1、可以使用jsonp解决跨域问题。
2、什么是jsonp?
Jsonp其实就是一个跨域解决方案。Js跨域请求数据是不可以的,但是js跨域请求js脚本是可以的。可以把数据封装成一个js语句,
做一个方法的调用。跨域请求js脚本可以得到此脚本。得到js脚本之后会立即执行。
可以把数据做为参数传递到方法中。就可以获得数据。从而解决跨域问题。
3、 jsonp的原理:
浏览器在js请求中,是允许通过script标签的src跨域请求,可以在请求的结果中添加回调方法名,在请求页面中定义方法,既可获取到跨域请求的数据。
什么是跨域:
1、Js是不能跨域请求。出于安全考虑,js设计时不可以跨域。
2、域名不同时。
3、域名相同,端口不同。
3、只有域名相同、端口相同时,才可以访问。
二、解决跨越问题
1、可以使用jsonp解决跨域问题。
2、什么是jsonp?
Jsonp其实就是一个跨域解决方案。Js跨域请求数据是不可以的,但是js跨域请求js脚本是可以的。可以把数据封装成一个js语句,
做一个方法的调用。跨域请求js脚本可以得到此脚本。得到js脚本之后会立即执行。
可以把数据做为参数传递到方法中。就可以获得数据。从而解决跨域问题。
3、 jsonp的原理:
浏览器在js请求中,是允许通过script标签的src跨域请求,可以在请求的结果中添加回调方法名,在请求页面中定义方法,既可获取到跨域请求的数据。
相关文章推荐
- ajax跨域请求:No 'Access-Control-Allow-Origin' header is present on the requested resource
- jquery ajax No 'Access-Control-Allow-Origin' header is present on the requested resource
- js跨域访问,no 'access-control-allow-origin' header is present on the requested resource
- 解决 js ajax跨域访问报“No 'Access-Control-Allow-Origin' header is present on the requested resource.”错误
- JS跨域:No 'Access-Control-Allow-Origin' header is present on the requested resource
- 本地Ajax跨域访问 No 'Access-Control-Allow-Origin' header is present on the requested resource.
- 解决 js ajax跨域访问报“No 'Access-Control-Allow-Origin' header is present on the requested resource.”错误
- 解决 js ajax跨域访问报“No 'Access-Control-Allow-Origin' header is present on the requested resource.”错误
- 解决 ajax跨域 No 'Access-Control-Allow-Origin' header is present on the requested resource.
- 解决“No 'Access-Control-Allow-Origin' header is present on the requested resource.”
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
- Vue报错笔记(2):No 'Access-Control-Allow-Origin' header is present on the requested resource.
- "No 'Access-Control-Allow-Origin' header is present on the requested resource" 问题
- No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin is therefore no
- ajax跨域(No 'Access-Control-Allow-Origin' header is present on the requested resource)
- “No 'Access-Control-Allow-Origin' header is present on the requested resource”
- No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '
- 跨域问题:No 'Access-Control-Allow-Origin' header is present on the requested resource.
- 跨域问题:“No 'Access-Control-Allow-Origin' header is present on the requested resource”
- No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '