Welcome Guest, Not a member yet? Register   Sign In
Call MVC Controller from with Javascript function
#3

[eluser]Matalina[/eluser]
You can't use php in an external javascript file unless your php parser parses .js files, or if you extranal script is a .php with a javascript header at the start, but you can't call ci code inside of the external javascript file unless it's processed through ci with a controller.

I tend to do this for my straight js files: Note: remove the index.php part if you are using .httaccess to remove it.
Code:
$url = [removed].href.toString();
re = /^(http:\/\/\w*\.*(\w+\.\w+)\/.*)\/*index\.php*/;
matches = re.exec($url)

var $base_url = matches[0];
var $img_url = matches[1];

You'll have to use XMLHttpRequest as well to process said script.

If your javascript is in the view then you can use php like you have it.


Messages In This Thread
Call MVC Controller from with Javascript function - by El Forum - 03-28-2012, 07:54 AM
Call MVC Controller from with Javascript function - by El Forum - 03-28-2012, 08:12 AM
Call MVC Controller from with Javascript function - by El Forum - 03-28-2012, 08:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB