Welcome Guest, Not a member yet? Register   Sign In
Best place to put jquery file
#1

[eluser]sooner[/eluser]
What is the best place to put the jquery file?should i create a folder under the system folder or outside of the system folder?how do i include the file in the views i tried to use base_url or site_url..nothing seem to work.i am not sure to generate the url in the src of the script tag.any suggestions plz
#2

[eluser]toopay[/eluser]
i think, CI doesnt care where you put your file, they had url helper.

in your view folder, on your files try this :

Code:
<html>
<head>
< script type="text/javascript" src="<?php
$ this ->load->helper('url');
echo site_url('your/js/folder/jquery-1.4.4.min.js');
?&gt;">< /script>
&lt; script type="text/javascript"&gt;
(function($) {
    $(document).ready(function() {
//Your rest jscript code
})(jQuery);
< /script>
&lt;/head&gt;
&lt;body&gt;
your jscript code should work here

&lt;/body&gt;
&lt;/html&gt;

remove space in '&lt; script type', '&lt; /script>' and '$ this ->'
Hope that help you.
#3

[eluser]toopay[/eluser]
This section maybe whats you needs :

Code:
&lt; script type="text/javascript" src="&lt;?php
$ this -&gt;load->helper('url');
echo site_url('your/js/folder/jquery-1.4.4.min.js');
?&gt;">< /script>

if you are try to include more than one files, you doesnt need to declare/load url helper anymore, in other word you may do that like this :

Code:
&lt; script type="text/javascript" src="&lt;?php
$ this -&gt;load->helper('url');
echo site_url('your/js/folder/jquery-1.4.4.min.js');
?&gt;">< /script>
&lt; script type="text/javascript" src="&lt;?php echo site_url('your/js/folder/yoursecondjsfile.js'); ?&gt;"&gt;&lt; /script>
&lt; script type="text/javascript" src="&lt;?php echo site_url('your/js/folder/yourthirdjsfile.js'); ?&gt;"&gt;&lt; /script>
#4

[eluser]metaltapimenye[/eluser]
Code:
[removed][removed]
[removed]
$(document).ready({
//mejik!
});
[removed]
#5

[eluser]metaltapimenye[/eluser]
Code:
&lt; script type="text/javascript" src="&lt;?php echo base_url();?&gt;js/jquery/1.4.2/jquery.min.js"&gt;&lt; /script>
&lt; script&gt;
$(document).ready({
//mejik!
});
< /script>
#6

[eluser]sooner[/eluser]
i tried both of yours it did not work i actually have my jquery file in system/javascript/jquery-1.4.4.min.js.

i did like this
[removed]load->helper('url');
echo site_url('javascript/jquery-1.4.4.min.js');
?&gt;">[removed]

if i view source the file [removed][removed]

but it does not load up the file
i used this [removed]< /script>

if i view source
[removed]< /script>

it does not load the file either

suggestions plz
#7

[eluser]Rob @ iFetch[/eluser]
Do you have a htaccess file that would be preventing access to the system directory?
#8

[eluser]Maglok[/eluser]
You shouldn't put scripts inside the system dir. The site_url() function points to controllers, not subdirectories.

The proper way is to make a scripts dir under your root and then do:

Code:
&lt; script type="text/javascript" src="&lt;?php echo base_url();?&gt;scripts/jquery.js"&gt;
#9

[eluser]Altaf Hussain[/eluser]
Hi,
I ma using my JavaScript file in different ways. If a JavaScript file is common to all, then i place it in data/js folder. Note that data folder is in the root of my CI installation.
Then where i need it i just place this code

[removed][removed]

Just modify that folder names and place it with yours, and it should work.
#10

[eluser]CroNiX[/eluser]
Why host it on your own server at all? Google hosts them for free and then the chances that someone else has been to a site with it and already has it cached is higher.
http://ajax.googleapis.com/ajax/libs/jqu...ery.min.js

You can also just make the links relative to your site root and not mess with base_url at all.
<skript type="text/javascript" src="/assets/js/scriptname.js" />




Theme © iAndrew 2016 - Forum software by © MyBB