我正在尝试使用引导程序对我的项目进行样式化,但是我一直得到一个CORS策略Error.My站点,它只显示没有样式的股票HTML。单击“添加到表”按钮不会打开模式。也不知道为什么加载样式。
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
<button type="button" class="btn btn-primary btn-lg btn-block" data-toggle="modal" data-target="#myModal">Add to Table</button>
</div>
</div>
<table class="table">
<thead>
<tr>
<th scope="col">Image</th>
<th scope="col">Name</th>
<th scope="col">Surname</th>
<th scope="col">Edit</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<!-- The Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">New message</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Recipient:</label>
<input type="text" class="form-control" id="recipient-name">
</div>
<div class="form-group">
<label for="message-text" class="col-form-label">Message:</label>
<textarea class="form-control" id="message-text"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Send message</button>
</div>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
</body>
</html>
这是错误。
CORS策略阻止了来自“https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css”的CSS样式表的https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css访问:对飞行前请求的响应没有通过访问控制检查:它没有HTTP状态。index.html:7GET https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css net::ERR_FAILED
有什么办法解决这个问题吗?
谢谢
发布于 2020-03-04 17:13:28
我也是新来的,我还不能评论,所以我正在回复。我不确定这是一个解决方案,但也许您可以使用不同的CDN URL?试一试,让我知道
编辑1,找到问题。modals需要引导的javascript插件才能工作。在jquery脚本下面添加以下代码。
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>编辑2: Fwlt (我应该解释得更多一些),您正确地使用了CDN,这就是引导样式起作用的原因,但是您想要使用的模式需要使用引导程序的JAVASCRIPT插件,这是我指示您添加的。当然,它命令使用您还需要链接到Jquery的引导js插件,然后您可以链接到引导JS。如果您计划也链接到popper.js ( id建议您做更多的功能而不是定位),仍然使用引导类,那么您必须在jquery和引导程序插件之间添加它。我还想让您知道,如果您计划添加一个css文件来添加您自己的样式,那么在您的文档头中的引导cdn之后添加它。
发布于 2022-04-03 07:53:59
您可以通过进入设置->构建来解决这个问题。执行、部署->调试器和设置允许在true上使用请求
https://stackoverflow.com/questions/60530222
复制相似问题