开发者

jquery and codeigniter

开发者 https://www.devze.com 2023-01-02 23:02 出处:网络
and sorry if that question is stupid I\'m trying to use javascript with codeigniter and I can\'t get it right

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


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


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)


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

0

精彩评论

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