我是 codeigniter 的新手,我面临一些问题。我使用核心 php 创建了一个商店定位器。它工作得很好。但我想将代码嵌入到 codeigniter 中。我复制了文件,当我尝试运行时,它不会在控制台中显示并显示以下错误。
GET http://xxx/application/views/webpages/storeLocator/storelocator.js net::ERR_ABORTED 403(禁止)
获取http://xxx/application/views/webpages/libs/handlebars.min.js net::ERR_ABORTED 403(禁止)
供您参考:我从https://www.softaox.info/jquery-store-locator-google-map-with-country-state-city-dropdown/
获取了代码我在 header.php 中添加了以下脚本路径
<script src="<?php echo base_url();?>application/views/webpages/libs/handlebars.min.js"></script>
<script src="https://maps.google.com/maps/api/js?key=xxxxx"></script>
<script src="<?= base_url();?>application/views/webpages/storeLocator/storelocator.js"></script>```
NB:base_url is correct, because it's working for others.Anyone please help me . I tried different things last couple of days.
您将 javascript 存储在视图文件夹中。视图文件夹应该只包含您的视图文件。
对于图像、CSS 和 javascript 等资源,您应该在根目录中创建一个文件夹,例如 public,其结构如下:
application
system
public
- css
- js
- img
然后在您的视图中使用基本网址加载 JavaScript 文件,如下所示:
<script src="<?php echo base_url('public/js/libs/handlebars.min.js') ?>"></script>
应用程序文件夹中的所有文件不应直接访问。您只能在上述文件夹之外访问您的index.php,并让它发挥其魔力。
公共文件应该位于应用程序和系统文件夹之外。总是。