javascript - 拒绝执行来自 'file_name.php' 的脚本,因为它的 MIME 类型 ('text/html' ) 不可执行,并且启用了严格的 MIME 类型检查

标签 javascript php html json header

我做一个网站。它在我的本地服务器上工作正常,但是当我将它上传到实时服务器时,它给了我这个错误:

Refused to execute script from 'http://www.mahijat.tk/new/wp-content/cache/autoptimize/autoptimize_c648c3203309d095775637e672c00239.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

我的站点 URL 是 http://www.mahijat.tk/new/

我的index.php文件代码是

<!doctype html>
<html lang="en-US" prefix="og: http://ogp.me/ns#" class="no-js ">

<head><meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:image" content="../pbs.twimg.com/profile_images/601407094277873664/WT2mk28E_400x400.jpg" />
<link type="text/css" media="all" href="wp-content/cache/autoptimize/autoptimize_ac4e9617d860b901a683f7676a3c44be.css" rel="stylesheet" />
<link type="text/css" media="all" href="wp-content/font-awesome/css/font-awesome.min.css" rel="stylesheet" />

最佳答案

这通常是一个 Chrome 错误,当您向返回 javascript 的页面发出 AJAX jsonp 请求但错误地发送了 Content-Type: text/html header 时,就会发生这种情况.

您可以通过更改 autoptimize_.....php 文件以在输出 javascript 之前发送正确的 Content-Type header 来修复它:

<?php
header('Content-Type: application/javascript');
// rest of the code

关于javascript - 拒绝执行来自 'file_name.php' 的脚本,因为它的 MIME 类型 ('text/html' ) 不可执行,并且启用了严格的 MIME 类型检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47113437/

相关文章:

html - Bootstrap 下拉菜单溢出而不是调整

javascript - 具有绝对位置的 HTML div 尝试换行文本。我可以避免它吗,不使用空格

javascript - 使用 extend.js 有什么好处?

javascript - 在python中发送javascript表单数据(post请求)?

php - CSS 类在 PHP 脚本后不起作用

php - PHP while 循环中没有条件?

php - 用户ID动态图片

javascript - iframe 和转换的不良行为

javascript - "export ' createNetworkInterface ' was not found in ' Apollo 客户端'

javascript - 了解 GSAP Accordion