-2

嘿,我得到了错误:

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,
];

如果我从终端尝试,这是我得到的 curl 响应

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 -->
4

1 回答 1

-1

设置标题:

'Content-Typet' 到 'application/javascript' 解决了这个问题。

于 2019-08-06T07:48:03.200 回答