Codeigniter - Autocomplete with Jquery (small article) |
[eluser]J. Brenne[/eluser]
Hey, i just wrote a small article about creating autocomplete with codeiginter and jquery. It's based on the Jquery Autocomplete Plugin of Bassistance.de. I searched a while for a working autocomplete and only found some old or bad tutorials or expliantions. So I testet around and found a way to realize it with reading from databse. I used MySQL for that. Thats why I wrote this article. If you want to see the original and with a complete ZIP download - can be found at: http://allover.worldattack.de/2009/01/25...th-jquery/ Lets start. You need for the the view: Code: $(function() { The controller: Code: class Autocomplete extends Controller { Now the model/autocomplete_model.php Code: class Autocomplete_model extends Model jquery.autocomplete.js The last thing is, you have to change the jquery.autocomplete.js into POST. So just — add type: “post”, –. That’s all! Code: $.ajax({ Thats all hope it was useful and sorry for my bad english. If you have any question - ask.
[eluser]Ssendol[/eluser]
Thanks lot, this is what I looking. Don't you have any demo and/or can you post DB ? I tried to use my onw DB, but not work. Thanks
[eluser]J. Brenne[/eluser]
Code: // go foreach The tablenames were callname and country. Test it. Have to work ![]()
[eluser]Ssendol[/eluser]
Thanks, I made a DB and tried again, but still not working. Sometimes 'Object expected' javascript error coming as '$(function() {' I added <script type="text/javascript" ... in _autocomplete.php all of js file of course. I think I miss something, but I have no idea. I am sorry to bother you, but I am too new about. Thank you again.
[eluser]J. Brenne[/eluser]
Kk here is there orginal script.. or a part of it. Load the javascript in your header. My Header looks like Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> My controller looks like: Code: function json_name() view [code] [removed] $(function() { function format(mail) { return mail.name + " (" + mail.to + ")"; } $("#airport_name").autocomplete('airport/json_name', { multiple: false, parse: function(data) { return $.map(eval(data), function(row) { return { data: row, value: row.name, result: row.name } }); }, formatItem: function(item) { return format(item); } }); }); [removed] [code]
[eluser]Skuja[/eluser]
I would like to note that you should run xss_clean check for $_POST data: Code: use
[eluser]Ssendol[/eluser]
Thank you for help. I checked line by line, but I can't find anything wrong. Anyway, javascript error came randomly as '; required' or 'name is null or'... I gave up ! :-S I must miss something, thank you again.
[eluser]Ssendol[/eluser]
It works with Chrome 1.0.154.46 and Firefox 3.0.5, but it not work IE 7(7.5730.13) OS is Window XP Pro SP3. Any idea ? Thanks.
[eluser]J. Brenne[/eluser]
I cant give you support to the js autocomplete. Its just jquery with a plugin. I only deisgned the controller and view. But no sorry I dont have a idea.
[eluser]Unknown[/eluser]
thanks brenne... but how can i passing extraParameters..? |
Welcome Guest, Not a member yet? Register Sign In |