Welcome Guest, Not a member yet? Register   Sign In
Javascript Nightmare
#1

[eluser]psdtocode[/eluser]
Hello,

I'm new to both CI and JS, however, I can't explain what is going on, and help from others isn't working. Basically, I am making a simple todo list, and I want to use JS/AJAX to get familiar with JS more. However, I'm having trouble just including JS files.

First, I was doing a relative path, such as src="prototype-1.0.6.2.js" (I've also tried jQuery), which didn't work. I then tried a couple different absolute paths, which didn't work as well. Finally, I searched on here and found a script_url helper (similar to a link_url()) helper, which doesn't work for me. Which ways are you able to include JS files (hopefully without a helper), because I can't seem to get it working.

I know it's not including because I can't use simple $() functions, and normal JS functions work (such as alert()Wink. In Safaris error viewer, it shows up an error when I try to use relative paths, and nothing shows up when I try to go to absolute paths. Any and all help is appreciated.

Just a note, I'm including it from a view file.

Thanks,
Andrew
#2

[eluser]usmc[/eluser]
Post some sample code.
#3

[eluser]psdtocode[/eluser]
Well, I've changed it several times, but for example, these won't work which I've tried:
script src="prototype-1.0.6.2.js" type="text/javascript"
script src="http://localhost:8888/index.php/home/prototype-1.0.6.2.js" type="text/javascript"
script src="http://localhost:8888/system/application/views/prototype-1.0.6.2.js" type="text/javascript"
#4

[eluser]usmc[/eluser]
Nothing showing up in your post.
#5

[eluser]psdtocode[/eluser]
For some reason, code wasn't working, and it wouldn't let me post the code. I put it on, but I have a '<' in the front of each one, and then '>&lt;/script&gt;' at the end.
#6

[eluser]xwero[/eluser]
Where are you storing the library? You should store the library in a public accessible directory. And then to make it easy on yourself switching from development server and back you can use the url helper function base_url()[path to file]prototype.js
#7

[eluser]psdtocode[/eluser]
I'm storing it in the view directory with all my other templates (which is why I thought a relative URL would work).

I tried using &lt;?=base_url();?&gt; infront of it, but that doesn't work either.
#8

[eluser]Michael Wales[/eluser]
All URLs are relative to index.php (as that is the file being retried upon every HTTP request to your CI application).
#9

[eluser]Crimp[/eluser]
Store assets like scripts and styles in web root. Call with the base_url() function to prefix your path (handy for changing from dev to live in config). Problem solved.
#10

[eluser]Michael Wales[/eluser]
Yeah, that's the method I like to take:
Code:
/
|- /assets
   |- /css
   |- /images
   |- /js

Then call those files with:
Code:
&lt;?php echo base_url(); ?&gt;/assets/css/style.css




Theme © iAndrew 2016 - Forum software by © MyBB