Laravel 5.7 CORB阻止问题

时间:2019-08-05 10:09:32

标签: php laravel cross-origin-read-blocking

嘿,我遇到了错误:

Cross-Origin Read Blocking (CORB) blocked cross-origin response ... with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.

我已经尝试了许多关于stackoverflow的修复程序,但是没有任何解决方法。

我现在在这里:

我已经使用以下配置安装了barryvdh / laravel-cors:

'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedOriginsPatterns' => ['*'],
'allowedHeaders' => ['*'],
'allowedMethods' => ['*'],
'exposedHeaders' => [],
'maxAge' => 0,

我正在控制器中加载中间件:

public function __construct()
{
    $this->middleware('cors');
}
public function code($id)
{
    $domain = \App\Domain::where('id', $id)->first();
    return view('code',compact('domain'));
}

它在我的Kernel.php中定义

    protected $routeMiddleware = [
    ...
    'cors' => \Barryvdh\Cors\HandleCors::class,
];

这是我从终端尝试时得到的卷曲响应

HTTP/2 200 
server: nginx/1.15.5
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
cache-control: no-cache, private
date: Mon, 05 Aug 2019 10:06:08 GMT
set-cookie: XSRF-TOKEN=eyJpdiI6Im05MnZ5K2IwS3Q3SnhQSDZ2a3lNMkE9PSIsInZhbHVlIjoia0RSZ1o2XC9IYkNTS3J2YlI2SWtrZUxXa2JSUThUcUhoR2FqSmN1aTYwZEpxQmp4ak5ORGJiRlQwdFJPNERlM0kiLCJtYWMiOiI2ZGJmMjFiMWM2OWQ0MDdkMDdjNWI5NTMyNGMzOTFhMmU4NGFiMjc2Zjg3NjExMjU0ZGM1M2MwODRiODI0MzZmIn0%3D; expires=Mon, 05-Aug-2019 12:06:08 GMT; Max-Age=7200; path=/
set-cookie: laravel_session=eyJpdiI6InZGekJCV2VUbEd0OFdpVWdzd0pzcXc9PSIsInZhbHVlIjoiXC9jb1JTTnJGV1FlNDhiVzB5dE43NnZCdHlaYlR6ZU82Wk1BclR5bWtVbUpZYWtGRTRGNDF3OEMrZ3J6eDJ1WFgiLCJtYWMiOiIwODE3YTY5NzZlNmQ2NTYzZjhhZWFkY2VjZTYxNGY2NmI1MDk4ZWM5MGE2Y2Q5MWI3N2UzMjEzMGFhNDVmZjA0In0%3D; expires=Mon, 05-Aug-2019 12:06:08 GMT; Max-Age=7200; path=/; httponly
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff

这就是我尝试加载页面的方式

function loadContent(url)
{
   var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
           xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("content").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}

document.addEventListener('DOMContentLoaded', function(event) {
  loadContent("https://xx.com/this/{{$domain->id}}")
})

我的路线是:

Route::get('/this/{id}', 'ThisController@code');

这是我从外部站点加载javascript文件的方式:

<!-- code --><div id="content"></div><script src="https://thissite.com/1"></script><!-- End code -->

1 个答案:

答案 0 :(得分:-1)

设置标题

从“ Content-Typet”到“ application / javascript”解决了这个问题。