admin 管理员组

文章数量: 1086019

File structure

index.js:

app.set("view engine", "ejs");

app.use(express.static("public"));

app.use(
  bodyParser.urlencoded({
    extended: true,
  })
);

chat.ejs

<body>
    <h1><%= (roomName) %></h1>
    
    <div id="video-grid">

    </div>
    
    
    <script src="script.js"></script>
</body>

while loading, error displayed

"The resource from “http://localhost:5000/chat/Aishu%20study/Aneesa/script.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)."

It works if I keep everything in the same html file. can someone help me with this? I'm not sure what the problem is

File structure

index.js:

app.set("view engine", "ejs");

app.use(express.static("public"));

app.use(
  bodyParser.urlencoded({
    extended: true,
  })
);

chat.ejs

<body>
    <h1><%= (roomName) %></h1>
    
    <div id="video-grid">

    </div>
    
    
    <script src="script.js"></script>
</body>

while loading, error displayed

"The resource from “http://localhost:5000/chat/Aishu%20study/Aneesa/script.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)."

It works if I keep everything in the same html file. can someone help me with this? I'm not sure what the problem is

Share Improve this question edited Sep 24, 2020 at 7:05 kiranvj 34.2k8 gold badges75 silver badges79 bronze badges asked Sep 24, 2020 at 6:53 AneesaAneesa 411 gold badge1 silver badge3 bronze badges 2
  • is script.js really a javascript file? also how e error message mentions some /xyz/ subdirectory in the url path, what most likely happened is that the path is incorrect and it matches some other general endpoint returning an html file you did not post in your answer – Krzysztof Krzeszewski Commented Sep 24, 2020 at 6:57
  • this is the error message "The resource from “localhost:5000/chat/Aishu%20study/Aneesa/script.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)." – Aneesa Commented Sep 24, 2020 at 6:59
Add a ment  | 

2 Answers 2

Reset to default 2

You should include Your public path like this:

app.use(express.static(__dirname+ '/public'));

And then implement your scripts and styles like this:

<script src="/script.js">

The issue lays in incorrect pathing in your application, you see the way you included script.js in the html file may have been correct if the paths were relative to the same folder. To be precise the ways you could define it are

The one you used "script.js" file is located in the same folder as the current page, it does not work the way you want it, since you are accessing the script tag from the localhost:5000/chat/Aishu%20study/Aneesa/xx url

<script src="script.js">

The "script.js" file is located in the scripts folder in the current folder

<script src="scripts/script.js">

The "script.js" file is located in the scripts folder at the root of the current web

<script  src="/scripts/script.js">

The "script.js" file is located in the folder one level up from the current folder

<script src="../script.js">

And lastly the one you should be using, the "script.js" file is located at the root of the current web

<script src="/script.js">

本文标签:

Error[2]: Invalid argument supplied for foreach(), File: /www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm, Line: 58
File: /www/wwwroot/roclinux.cn/tmp/route_read.php, Line: 205, include(/www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm)
File: /www/wwwroot/roclinux.cn/tmp/index.inc.php, Line: 129, include(/www/wwwroot/roclinux.cn/tmp/route_read.php)
File: /www/wwwroot/roclinux.cn/index.php, Line: 29, include(/www/wwwroot/roclinux.cn/tmp/index.inc.php)