can't get autocomplete value |
[eluser]titolancreo[/eluser]
Hi! I want to have an autocomplete input and I choose jquery. I have two problems: 1. On my controller, i try to get term value but I always get 0. 2. If I recieve elements, I can`t see anything, but If I click, it works. I have not CSRF This is my javascript Code: [removed] This is my controller. if I'm debbuging, I can see that "$term " is boolean and 0, and I need the text writen by the user. Code: if($this->session->userdata('logged_in')) So, how can I have in $term the string? How can I see all names in autocomplete (See photo) Thanks!!!
[eluser]TheFuzzy0ne[/eluser]
What is your response() function? By default, jQuery uses GET to query the server. If you're sending data, you should use POST. If you have Firefox, have you tried the Firebug extension? It's very handy for debugging problems like this.
[eluser]titolancreo[/eluser]
I don't know what else I need to do, I only have what you see. I thought that response function was on jquery code, but because of your ansewer, maybe I have to write it... I know that it uses get, but I want to do it with post, and that's not my problem, because it works (more and less) if I send "as" for example, I can't get it, but I get first 10 rows from my database instead of the 10 rows that contains "as". At the endo of controller I send it by echo json_encode and it works, because I can see them with Firebug and also, with alerts, but I don't know why, I can't see this 10 names in the dropdown menu. So, I want to know why in my controller, at this line <code>$term = $this->input->post('term');</code> I get $term as a boolean with value 0 instead of a string with value "as"
[eluser]TheFuzzy0ne[/eluser]
Have you checked that the correct term is being sent to the server? Also, does changing this: Code: data: { term: $("#autocomplete").val()}, to this: Code: data: { term: $(this).val()}, make any difference?
[eluser]titolancreo[/eluser]
I think my error is sending because I use the same ajax function to send other things, but without autocomplete. If I change it to $(this).val, there is an error, because jquery cannot call method 'toLowerCase' of undefined. I changed <code>$buscar = $this->input->post('term');</code> to <code> $buscar = $this->input->get('term');</code> and now it works, but why? I have enable_query_strings= FALSE Maybe should I change my controller? Code: $list = $this->DaoAutocomplete->autocomplete($term); //it returns 10 names
[eluser]TheFuzzy0ne[/eluser]
If you're using GET, you may run into problems with characters that aren't allowed in the URL, so I'd recommend using POST instead. Also, it would keep your controller cleaner if you had your model return the JSON encoded string, or even output it directly. I agree. Your model/controller should only be echoing a JSON array of strings only, not IDs.
[eluser]titolancreo[/eluser]
I couldn't do it with autocomplete... so I did myself with a normal ajax call.
[eluser]TheFuzzy0ne[/eluser]
If you get stuck, try comparing your code to the example on the Web site. http://jqueryui.com/autocomplete/
[eluser]titolancreo[/eluser]
That was the first thing I did. I also tried copying it but it doesn't work. Anyway, it doesn't matter, I can't spend more time on it, I did it myself. Thanks! |
Welcome Guest, Not a member yet? Register Sign In |