Calling a CI library from a javascipt? |
[eluser]Ray Julich[/eluser]
I am adding an AJAX autocomplete to my CI site, which uses a javascript include. Inside the javascript, it includes a .php file. Code: this.ajaxTarget = 'Autocomplete.php';
[eluser]smilie[/eluser]
Hm, if it is .js file, I wouldn't know. I also use (sort) of Ajax (RESTFull API), but my JS code is withing .php file, therefore I can do: var somesession_data = "<?=$this->session->userdata('bla');?>"; But from .js file I wouldn't know... Cheers, Smilie
[eluser]Krzemo[/eluser]
Make request to an url and let controller get your data in any of those: json, xml, html, text etc.
[eluser]jalalski[/eluser]
I have a controller (application/controllers/admin/customers.php) that has a bunch of methods for working with customers. One of the methods is 'find_like' which then calls a search on the Customers model and returns json_encoded string to the caller: Code: class Customers extends Controller { This function is then available to the caller as: index.php/app/admin/customers/find_like/ Remember to tell ajax to use POST, not GET for the autocomplete.
[eluser]LuckyFella73[/eluser]
Derek Allard did a nice tutorial how to implement autocomplete in a CI website: http://video.derekallard.com/ Under "Downloads" you can even get the complete code and adjust to your needs. It is based on: Scriptaculous and prototype btw. |
Welcome Guest, Not a member yet? Register Sign In |