Pergunta

I'm using Jquery tag-it to get a list of keywords from a remote json string - this works fine.

However what I've now got is a situation where instead of jquery 'drilling down' as you type its trying to do a search query on

somefile.php?q=foo

(foo being what you've just typed. This would drill-down the tag list to only show those with 'foo' in them.

I'm using Laravel 4, so I need to basically change the ajax request so that it instead does /somefile/foo. Is there any way of doing this? I've been searching around like crazy but cant find a solution.

For reference, here's the tag-it code I currently have:

$("#tags").tagit({
    autocomplete: {delay: 0, minLength: 2},
    allowSpaces: true,
    onlyAvailableTags : false,
    tagSource: function(search, showChoices)
    {
        var that = this;
        $.ajax({
            url:        "/admin/keywords/autocomplete",
            data:   { term:search.term },
            dataType: "json",
            success:    function(choices)
            {
                showChoices(that._subtractArray(choices, that.assignedTags()));
            }
        });
    }
});
Foi útil?

Solução

Ok I think I've managed to work this out myself through trial and error - this now works.

I've tweaked my Laravel routing so that the following path will do a '%LIKE%' sql query on anything thrown at it:

http://domain.com/admin/keywords/autocomplete/search/{term}

Using this I modified the ajax call within the tagit plugin to instead just append the input to the end of the url. The final code looks like this:

$("#tags").tagit({
    autocomplete: {delay: 0, minLength: 2},
    allowSpaces: true,
    onlyAvailableTags : false,
    tagSource: function(search, showChoices)
    {
        var that = this;
        $.ajax({
            url:        "/admin/keywords/autocomplete/search/" + search.term,
           // data:   { term:search.term },
            dataType: "json",
            success:    function(choices)
            {
                showChoices(that._subtractArray(choices, that.assignedTags()));
            }
        });
    }
});

This does seem to work, and is surprisingly snappy. I know there is likely a better way to do this, however this is the best I could do for now.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top