In my project, I am trying to create a autocomplete effect using the following plugin:
This plugin is working fine until I don't add space into my textbox (after adding a word). and when I just delete the entered word using backspace then the autocomplete is showing the previous list which should have shown before.
PS: Every time I am passing the full text of the text field to server through ajax call which is necessary in my application.
Here is my code:
JS Fiddle (not working because of ajax url)
JS
$(function () {
    var result = $('#result');
    var contents = {
        value: "",
        data: ""
    };
    /* Ajax call */
    result.keydown(function (event) {
        if (!event.shiftKey) {
            var sugData;
            var text = result.val(); //.split(" ").pop();
            //console.log(text);
            /* Send the data using post and put the results in a div */
            $.ajax({
                url: "http://localhost:9999/projects/1/autocomplete/suggestions",
                type: "POST",
                data: "drqlFragment=" + text, // + "  ",
                //data: "drqlFragment=when node_database_property  ",
                async: false,
                cache: false,
                headers: {
                    accept: "application/json",
                    contentType: "application/x-www-form-urlencoded"
                },
                contentType: "application/x-www-form-urlencoded",
                processData: true,
                success: function (data, textStatus, jqXHR) {
                    var resData = data.suggestions;
                    //console.dir(resData);
                    for (var i = 0; i < resData.length; i++) {
                        resData[i].value = resData[i].keyword;
                    }
                    sugData = resData;
                    //console.dir(sugData);
                },
                error: function (response) {
                    //console.dir(response);
                    $("#result").val('there is error while submit');
                }
            });
            console.dir(sugData);
            $('#result').autocomplete({
                lookup: sugData
            });
        }
    });
});
HTML
<form id="foo">
    <textarea id="result" rows="4" cols="50"></textarea>
    <input type="submit" value="Send" />
</form>
Sorry, I can't provide you the json data because it is being modified by the server whenever I press a key. (So, actually it is an object variable returning by the server on ajax call).
