Ajax Controller |
Hi at all,
I'm new with CI but not very with MVC models so I wanted to have a dedicated Controller called Ajax to handle all Ajax requests as I did in a homemade framework. When I want to use Ajax I'm already in a Controller and the request gives a 404 to http://xxxx/currentcontroller/ajax/mymethod. I can understand that the current controller is in the URI because of relative path. I have found on the web that people usually write Ajax requests in a view in order to have the base_url() or site_url() available to build correctly the URI, but in my case, I want my Ajax requests in a javascript file. Is there a solution to reach http://xxxx/ajax/mymethod without writing the js code in a view or writing absolute paths in Ajax URL parameter ? Cheers Max
At the beginning ot the head section of your HTML template you may place the following JavaScript:
Code: <script type="text/javascript"> The variable site_url will be available to the other JavaScripts within the page then, including your AJAX calls.
It is not my idea, I took it from another project. https://github.com/pyrocms/pyrocms/blob/...er.php#L84
|
Welcome Guest, Not a member yet? Register Sign In |