开发者

How to add and use an external js file in Codeigniter?

I am trying to add an external javascript file to Codeigniter application.

I have placed my external js file in the "projectname/js/" folder.

Below is 开发者_开发百科the script tag src in my view page. src="http://localhost/needpcbcodeigniter/js/registration.js">

But I am getting a "Not found" error for the js file.


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)

Check your .htaccess to make sure it doesn't redirect when a valid filename is requested. Check it here


You should add an external javascript file to codeigniter in assets folder.

You should check some following steps :-

1) first fix your project base_url which is set in application/config/config.php like-

$config['base_url'] = 'http://localhost/yourprojectname/'

2) create a folder(e.g: js) in assets folder(at root of folder) for save all javascript files(e.g : registration.js).

3) on final step where you want to use javascript file use code like this-

<script src="<?php echo base_url();?>/assets/js/registration.js"></script>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜