解决[origin 'http://xxx.xxx.com:xxxx' has been blocked by CORS policy: The request client is n
Posted 挖穿地球
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决[origin 'http://xxx.xxx.com:xxxx' has been blocked by CORS policy: The request client is n相关的知识,希望对你有一定的参考价值。
跨域报错解决方案Access to XMLHttpRequest at ‘http://xxx.com/xxx‘ from origin ‘null‘ has been blocked by
错误背景描述:
在使用ajax调用api接口的时候:发生错误如下
Access to XMLHttpRequest at ‘http://xxxx.com/xxx’ from origin ‘null’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
发生错误的ajax代码如下:
$.ajax(
url: 'http://xxx.com/xxxxx',
type: 'POST',
dataType: 'json',
success:function(data)
console.log(data)
);
错误发生原因:
这是一个资源跨域问题。
解决方法:
很简单。把dataType的json改为jsonp。
$.ajax(
url: 'http://xxx.com/xxxxx',
type: 'POST',
dataType: 'jsonp',//这里修改成jsonp
success:function(data)
console.log(data)
);
以上是关于解决[origin 'http://xxx.xxx.com:xxxx' has been blocked by CORS policy: The request client is n的主要内容,如果未能解决你的问题,请参考以下文章
Repository “http://xxx@git.xxx.net/xxx/xxx.git”not found 解决
ERROR: Error fetching remote repo 'origin' 错误解决
nuxt.js 本地开发跨域问题(Access-Control-Allow-Origin)及其解决方案
No 'Access-Control-Allow-Origin' header is present on the requested resource这个怎么解决啊?
解决Jenkins上git出现的“ERROR: Error fetching remote repo 'origin'”问题