[英]How to add and use an external js file in Codeigniter?
I am trying to add an external javascript file to Codeigniter application. 我正在尝试将外部JavaScript文件添加到Codeigniter应用程序。
I have placed my external js file in the "projectname/js/" folder. 我已将外部js文件放在“projectname / js /”文件夹中。
Below is the script tag src in my view page. 下面是我的视图页面中的脚本标记src。 src="http://localhost/needpcbcodeigniter/js/registration.js">
SRC = “HTTP://localhost/needpcbcodeigniter/js/registration.js”>
But I am getting a "Not found" error for the js file. 但我收到js文件的“未找到”错误。
Most probably this is because the apache mod_rewrite is dealing with the js folder as a codeigniter controller name (as if you're calling http://localhost/projectname/index.php/js/registration.js ) 很可能这是因为apache mod_rewrite将js文件夹作为codeigniter控制器名称处理(就好像你正在调用http://localhost/projectname/index.php/js/registration.js )
Check your .htaccess to make sure it doesn't redirect when a valid filename is requested. 检查.htaccess以确保在请求有效文件名时它不会重定向。 Check it here
在这里查看
You should add an external javascript file to codeigniter in assets folder. 您应该将外部javascript文件添加到assets文件夹中的codeigniter。
You should check some following steps :- 您应该检查以下几个步骤: -
1) first fix your project base_url
which is set in application/config/config.php
like- 1)首先修复你的项目
base_url
,它在application/config/config.php
-
$config['base_url'] = 'http://localhost/yourprojectname/'
2) create a folder(eg: js) in assets
folder(at root of folder) for save all javascript files(eg : registration.js). 2)在
assets
文件夹(文件夹的根目录)中创建一个文件夹(例如:js),用于保存所有javascript文件(例如:registration.js)。
3) on final step where you want to use javascript file use code like this- 3)在最后一步你要使用javascript文件使用这样的代码 -
<script src="<?php echo base_url();?>/assets/js/registration.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.