今天用chrome打開了一個(gè)微博的鏈接:不靠譜的程序員代碼能坑到什么程度,看看我的經(jīng)歷
為啥不用火狐,參見本人文章霧霾了?新浪微博H5前端的bug:
評論區(qū)一片空白。F12一下慎皱,果然:
image.png
'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
這個(gè)問題在用Vue.js 的時(shí)候遇到過。似乎jQeury沒有這個(gè)問題叶骨。
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就可以了。