mic*_*ith 6 html javascript jquery express
我正在尝试使用 express 和 ajax 在测试站点上测试一些 api 调用,但是如果我将 js 脚本分成自己的文件,则会出现以下错误,
由于 MIME 类型(“text/html”)不匹配(X-Content-Type-Options:nosniff),来自“ http://localhost:9000/userProfileFunctions.js ”的资源被阻止。
如果我将所有内容都保存在同一个 html 文件中,它会起作用,但这更像是解决问题的创可贴。我什至将 express app.use 标头设置为“X-Content-Type-Options: nosniff”,但它仍然不起作用
主文件
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous">
</script>
<script src="userProfileFunctions.js" ></script>
</head>
<body>
<form>
<h4>GET REQUEST USERS PROFILE</h4>
UUID: <input id="getUserInput" type="text" name="UUID"><br>
<input id="getUserProfile" type="button" value="submit">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
应用程序.js
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11988 次 |
| 最近记录: |