Welcome Guest, Not a member yet? Register   Sign In
Ajax - relative URLs and links?
#1

[eluser]mattpointblank[/eluser]
Hi all.

I'm porting an AJAX app into my newly CI-powered site.

Having big issues getting things to work. I've made an 'assets' folder in the CI root directory and used this to store all my CSS, images, scripts, etc. One of my AJAX javascript files sits in this folder, and contains relative links to images. None of these display on my page, which I assume is to do with my controller URL structure.

Since the file containing the links is javascript, I can't use something like base_url() to construct the path, as I've been doing in my views. Is there a standard good practice method for things like this? In other places I have to run code like this:

Code:
http.open("POST",'/dev/codeigniter/system/application/helpers/event_finder_by_postcode_helper.php',true);

which feels ugly, whereas in the non-CI site it was just:

Code:
http.open("POST",'inc/event_finder_by_postcode_helper.php',true);

Can anyone tell me if there's a better way to do this kind of thing? AJAX stuff is the only time with my CodeIgniter development that I've found the framework frustrating, so far.
#2

[eluser]rogierb[/eluser]
I packed all the ajax stuff in several ajax controllers. The js I put in viewfiles or js files included in the view.
This way I just call ajax with something like base_url/()."my_ajax_controller/postal_code_finder"

In your case you'll have to rewrite to use controllers.
#3

[eluser]Berserk[/eluser]
or you can add an js variable in view :

<code>
[removed]
var BASE_URL = '&lt;?=$base_url?&gt;';
[removed]
</code>

then use it in your js function:
<code>
BASE_URL+'ajax_controller'
</code>




Theme © iAndrew 2016 - Forum software by © MyBB