Welcome Guest, Not a member yet? Register   Sign In
BSN AJAX auto-suggest with CI
#1

[eluser]NogDog[/eluser]
Figured I'd share this here in case it helps anyone else out.

I've been spending much of the last 24 hours looking for an auto-suggest JavaScript I could use for a couple form text fields. I wasn't having much luck, but finally got this one to work: http://www.brandspankingnew.net/archive/...st_v2.html

I had to make one small change in the JavaScript file, getting rid of where it assigns a varname= to the URL, allowing me to use CI "friendly" URLs:
Code:
// create ajax request
    //
    if (typeof(this.oP.script) == "function")
        var url = this.oP.script(encodeURIComponent(this.sInp));
    else
        // var url = this.oP.script+this.oP.varname+"="+encodeURIComponent(this.sInp);
        var url = this.oP.script+encodeURIComponent(this.sInp);
Then in the page (view) itself, I can reference the CI controller I want it to call as:
Code:
[removed]
// <![CDATA[
    var options = {
        script:"/index.php/ajax/author_auto_complete/",
        json:true
    };
    var as_json = new bsn.AutoSuggest('author', options);

// ]]>
[removed]
Note the trailing "/" at the end of the url, where "ajax" will be the controller, "author_auto_complete" the method, and then the script will add the string after that which will be the one argument to that method.

Hope that saves someone else a few hours. Smile
#2

[eluser]bretticus[/eluser]
I had the same issue getting jQuery Autocomplete plugin 1.1 to work a few weeks back. Fortunately, the fix was easy, just changed default action to post:
Code:
function request(term, success, failure) {
        //... {edited out for brevity}
            
            $.ajax({
                                // using post for CI (brett)
                                type: 'post',
                // try to leverage ajaxQueue plugin to abort previous requests
                mode: "abort",
                // limit abortion to this input
                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);
                }
            });//... {edited out for brevity}
    };
#3

[eluser]jcavard[/eluser]
@bretticus: would you have the link to get that plugin? a quick google search showed up a few pages with all the same name... sine you got this one working with CI, I would like to have the same as you.

thanks man.
#4

[eluser]bretticus[/eluser]
[quote author="jcavard" date="1253670637"]@bretticus: would you have the link to get that plugin? a quick google search showed up a few pages with all the same name... sine you got this one working with CI, I would like to have the same as you.

thanks man.[/quote]

This link seems to have the same code. The ajax call is on line 361.




Theme © iAndrew 2016 - Forum software by © MyBB