Welcome Guest, Not a member yet? Register   Sign In
Error with javascript
#1

[eluser]Sein Kraft[/eluser]
I've the next line in the view header.php

Code:
< script type="text/javascript" src="<? php echo base_url(); ?>'script.js">< /script >

and the script doesn't work. But in the code work fine because if I replace base_url() with the directory 'http://localhost/KL6G56PD8P/' works without problem.

The strange thin is viewed from source code of the webbrowser the tag < scritp > has the same content in the two ways. But with '&lt;? php echo base_url(); ?&gt;' the script doesn't work.
#2

[eluser]TheFuzzy0ne[/eluser]
Is your script.js file not in a subdirectory in your Web root?

I'm also wondering if that space between the &lt;? and php is responsible.
#3

[eluser]Sein Kraft[/eluser]
Is in the webroot, also i know the spane but to post and avoid the censor of the forum i add the space.

base_rul() = 'http://localhost/KL6G56PD8P/'

if i remove the echo base_url() an put 'http://localhost/KL6G56PD8P/' works fine
#4

[eluser]CroNiX[/eluser]
And what is your base_url set to in your config? Does it have a trailing slash like "http://localhost/KL6G56PD8P/"?
#5

[eluser]Sein Kraft[/eluser]
Yes it has.
I've changed to this and now works fine.
Code:
&lt;?php echo '&lt; script type="text/javascript" src="'.base_url().'script.js"&gt;&lt;/ script >'; ?&gt;
#6

[eluser]TheFuzzy0ne[/eluser]
You should not have to do that. Pasting the code you posted above into a view resulted in a parse error, caused by the space between the &lt;? and the php.




Theme © iAndrew 2016 - Forum software by © MyBB