[eluser]fchristant[/eluser]
hi,
I'm thoroughly enjoying using CI for a large project. I've learned a lot from practice, the documentation and forum but still have quite a simple question...
Inside my javascript files, how can I refer to the CI application path? Here's some of my code:
Code:
var postURL = "<?php $CI =& get_instance(); $CI->load->helper('url'); site_url("json_username_check"); ?>/" + username + "/" + new Date().getTime();
$.ajax({
type: "POST",
url: postURL,
success: function(msg) {
result = (msg=='TRUE') ? true : false;
}
});
It's about the first line really. As you can see I'm trying all sorts of things to get a handle to CI's application path from within javascript. Compliant with best practices I have the js files inside the webroot (js dir) and the CI files outside the webroot. From my views I reference the JS files and this works fine. I have the following .htaccess inside the webroot:
Code:
RewriteEngine on
RewriteRule ^$ /apps/OS4W/html/index.php [L]
RewriteCond $1 !^(index\.php|images|img|css|js|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /apps/OS4W/html/index.php/$1 [L]
And the following .htaccess in the webroot/js dir:
Code:
AddHandler application/x-httpd-php .js
php_value auto_prepend_file gzip-js.php
This last .htaccess is not really relevant for my question, it's purpose is to automatically compress my js files.
As mentioned, the problem is here:
Code:
var postURL = "<?php $CI =& get_instance(); $CI->load->helper('url'); site_url("json_username_check"); ?>/" + username + "/" + new Date().getTime();
The site_url function is not a valid function, it is not recognized. Loading the URL helper does not help either. I also cannot get an instance to the CI object. I suspect this is due to the .htaccess but I'm not sure how to fix this without having other unwanted impact.
Thanks in advance for anyone offering help