Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] base_url in javascript
#1

[eluser]predat0r[/eluser]
Hi there,

Time has come to put all of my JQ scripts to an external js file, I set a base_url variable for js in php, and referenced on it in js file, but the variable has some char addition inside..
In FireBug I see a plus '% 20' (with no spaces) in the url and that's because my scripts can't work.
So, in FireBug console is shown: POST http://localhost/site/ % 20controller/method
How can I remove this % item? Thanks

Code:
<.script>
/* &lt;![CDATA[ */
   var base_url = "&lt;?php echo base_url(); ?&gt;";
/* ]]> */
<./script>

and js

Code:
...
$.ajax({
    url: base_url + 'shop/autocomplete',
    dataType: 'json',
...
#2

[eluser]Unknown[/eluser]
'% 20' is due to spaces.trim the values before submiting.
#3

[eluser]predat0r[/eluser]
[quote author="InnovativePhp" date="1296773048"]'% 20' is due to spaces.trim the values before submiting.[/quote]

Hmm, what to trim? base_url is fix, the other part (controller/method) is too.
But I tried to trim base_url in javascript but nothing good..

EDIT: if I hardcode the url in js, it works. So the concatenation should put some extra char but why?!?
#4

[eluser]predat0r[/eluser]
Solution: I have to put the ending php tag next to semicolon, this way all OK!
&lt;?php echo base_url();?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB