jquery and codeigniter

痴心易碎 提交于 2020-01-14 13:56:47

问题


and sorry if that question is stupid I'm trying to use javascript with codeigniter and I can't get it right what I'm actually doing is placing jQuery inside the views folder and call it from one of my view files like that:

<script type="text/javascript" src="jquery.js"></script>

I get no response no errors it just doesn't work, I could also display more code but my first assumption is that there something wrong with the way I call it... maybe something with the paths?

any workarounds?

thanks in advance


回答1:


Place jquery.js in your website root and use:

<script type="text/javascript" src="/jquery.js"></script>

If you want to put it say in a js folder, place the folder in root and do:

<script type="text/javascript" src="/js/jquery.js"></script>

Or you can try this:

<script type="text/javascript" src="<?=base_url();?>js/jquery.js"></script>

as described here




回答2:


Also consider that if you use Codeigniter's default .htaccess configuration suggested in the Codeigniter URLs page:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

you won't be able to access a jquery.js file as a request for that resource will be rewritten to index.php; if this is a case you have to add that file as an exception:

RewriteCond $1 !^(index\.php|images|jquery\.js|robots\.txt)



回答3:


i just want to add these tips from bretticu (in ellilab) beCause i was in a normal way using base_url();

That was running for my css, but not for my .js in a folder placed in the root. So, after few gnashing of teeth and hair loss, i 've added two line in may htaccess before, now it's perfect.

RewriteEngine on RewriteCond $1 !^(index\.php|css|images|js\.js|robots\.txt|favicon\.ico) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [L]

Here is the post of Bretticus: enter link description here



来源:https://stackoverflow.com/questions/3022796/jquery-and-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!