ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Using autocomplete with remote soure

September 14, 2011 8:45am

Subscribe [1]
  • #1 / Sep 14, 2011 8:45am

    Josh Holloway

    41 posts

    I’m looking to implement the jquery-ui autocomplete into a site I’m building for a client yet seem to be having some issues.

    Here’s the auto complete code:

    $.widget( "custom.catcomplete", $.ui.autocomplete, {
            _renderMenu: function( ul, items ) {
                var self = this,
                    currentCategory = "";
                $.each( items, function( index, item ) {
                    if ( item.category != currentCategory ) {
                        ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                        currentCategory = item.category;
                    }
                    self._renderItem( ul, item );
                });
                
            }
        });
        
        $(function() {
                $("input[name=keywords]").autocomplete({
                delay        : 0,
                source        : "{site_url}_shared/autocomplete/"
            });
        });

    This doesn’t work. However, if I remove the source and change it to: “search.php” it does.

    Both the autocomplete template and search.php contain the following:

    <?php
        $data = array(
            array(
                'label'        => "anders",
                'category'    => "",
            ),
            array(
                'label'        => "anders",
                'category'    => "",
            ),
            array(
                'label'        => "antel",
                'category'    => "",
            ),
            array(
                'label'        => "annhhx10",
                'category'    => "Products",
            ),
            array(
                'label'        => "annk K12",
                'category'    => "Products",
            ),
            array(
                'label'        => "annhhx10",
                'category'    => "Products",
            ),
            array(
                'label'        => "annttop C1",
                'category'    => "Products",
            ),    
            array(
                'label'        => "annhhx10",
                'category'    => "Products",
            ),
            array(
                'label'        => "anders andersson",
                'category'    => "People",
            ),
            array(
                'label'        => "andreas andersson",
                'category'    => "People",
            ),    
            array(
                'label'        => "andreas johnson",
                'category'    => "People",
            ),
        );
        echo json_encode($data);
    ?>

    PHP parsing is turned on for the template…

    I’m not sure what could be causing this. If i actually navigate to the URL the template resides at it displays the data and jslint returns the data as valid json.

    If anyone has any ideas it would be appreciated.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases