• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[ASK] Integrating CI and Jquery autocomplete plugin

#1
[eluser]Aria Rajasa[/eluser]
Hi all, I am trying to use the jquery autocomplete plugin and found a bit of stuck here. It seems that the plugin uses a $_GET parameter and therefore can't work with the CI URL re-routing. It calls url like this:

http://localhost/SITE/controller/search_fullname?q=joko&limit=10&timestamp=1219101506002

I can't get the variable q to work, but if I can rewrite the url to let's say:

http://localhost/QMIT/plan/search_fullname/joko

then I can just adjust the controller to work accordingly, any hints?

TIA

#2
[eluser]gon[/eluser]
Hi,

You can edit the autocomplete plugin to make it use POST.
Just add

type: "post",

to the configuration object sent inside $.ajax( statement, inside request() function.



Or you can enable $_GET this way. I have used it without any problem.

Cheers

#3
[eluser]Aria Rajasa[/eluser]
Thank you so much <b>gon</b> for the reply. I use your solution and change it to post and now it works! Thanks again!

#4
[eluser]San2k[/eluser]
Hi! I started to work with CI yesterday.

Could you please write a little example of how did you realized this autocomplete feature in CI?

Here where iam stuck - $("#suggest1").autocomplete('/data_work/search_username/',type:"post");
});

So data_work is a cntroller. search_username - function. This function will search for usernames in DB and return it to autocomplete.

I dont know what to do next. I think its necessarily to do something with CI URI routing, but i dont know what exactly Smile

#5
[eluser]Aria Rajasa[/eluser]
I am using the jquery autocomplete and edit the jquery.autocomplete.js. I search for:

Code:
$.ajax({type: "get"...

and edit the "get" to "post", and it works! I also encountered another problem with thickbox. So I used the "activating the get functionality" that was also recommended and it also works Big Grin

Hope it helps

#6
[eluser]San2k[/eluser]
Yep, did it! Thanks alot!

#7
[eluser]GrootBaas[/eluser]
Hi all,

I seem to have the same issue, but I can not find
Code:
$.ajax({type: "get"
anywhere in the jquery.autocomplete.js.

Please can someone help me in the right direction.

Thanks in advance,

#8
[eluser]Aria Rajasa[/eluser]
search for

Code:
$.ajax({mode: "abort",port: "autocomplete" + input.name,

and add type: "post" like this

Code:
$.ajax({type: "post", mode: "abort",port: "autocomplete" + input.name,

Works for me

#9
[eluser]GrootBaas[/eluser]
Guys,

Thank you so much for your help. You really make a difference in somebody's live with the fast and educated replies. Thank you all again.

For the next person who comes across this problem ...

Inside jquery.autocomplete.js

Change
Code:
$.ajax({mode: "abort",
    port: "autocomplete" + input.name,
    dataType: options.dataType,
    url: options.url,
    data: $.extend({
    q: lastWord(term),
    limit: options.max
    }, extraParams),
    success: function(data) {
    var parsed = options.parse && options.parse(data) || parse(data);
               cache.add(term, parsed);
             success(term, parsed);
                }
});

to this ...

Code:
$.ajax({type: "post",
        mode: "abort",
    port: "autocomplete" + input.name,
    dataType: options.dataType,
    url: options.url,
    data: $.extend({
    q: lastWord(term),
    limit: options.max
    }, extraParams),
    success: function(data) {
    var parsed = options.parse && options.parse(data) || parse(data);
               cache.add(term, parsed);
             success(term, parsed);
                }
});

Then in your controller, change ....

Code:
$q = strtolower($_GET["q"]);
to
Code:
$q = strtolower($_POST["q"]);

#10
[eluser]mikeyhell[/eluser]
Adding type: "post", in jquery.autocomplete.js throws an error:

missing } in compound statement

Anyone know why? This seemed to work before and my JS skills aren't good enough to track it down.

Thanks


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.