今天用chrome打开了一个微博的链接:不靠谱的程序员代码能坑到什么程度,看看我的经历
为啥不用火狐,参见本人文章雾霾了?新浪微博H5前端的bug:
评论区一片空白。F12一下,果然:
'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
这个问题在用Vue.js 的时候遇到过。似乎jQeury没有这个问题。
stackoverflow给出一些解释:
其中
If you are using PHP, try to add the following code at the beaning of the php file:
if you are using localhost, try this:
header("Access-Control-Allow-Origin: *");
if you are using external domains such as server, try this:header("Access-Control-Allow-Origin: http://www.website.com");
新浪恰恰是PHP搞的,加一句header就可以了。