1

I am trying to load in my jquery autocomplete data from a text file, to reduce page load size. I am trying:

<script type="text/javascript">
    $(document).ready(function(){
            var practitioner_data = new Array();
            $.get("/live_practitioners.txt", { },
            function(data){
                var data_array = new Array();
                data_array = data;
                $("#search_therapist_name").autocomplete(data_array, {minChars: 1, matchContains: true, mustMatch: true, selectFirst: false, formatItem: function(item) { return item.text; } }).result(function(event, item) { document[\'' . $str_form_name . '\'].counsellor_id.value=item.counsellor_id; });
            });
    });
</script>

Firebug shows me a first request to the txt file, and the data looks correctly formatted:

[{text:'Dr. Tania Abdulezer', counsellor_id:'877'}, {text:'Helen Acton', counsellor_id:'712'}]

However when I start typing into the text box, firebug is showing me a request being made, for each new letter typed, going to:

http://rscpplocal/%5B%7Btext:%27Dr.%20Tania%20Abdulezer%27,%20counsellor_id:%27877%27%7D,%20%7Btext:%27Helen%20Acton%27,%20counsellor_id:%27712%27%7D%5D?q=r&limit=10&timestamp=1296041901116

Firstly, I am not sure why it is making a new request each time, I thought the point of loading it in from a string, to then supply as data, was so only one request was needed. Secondly, I have no idea why those subsequent requests, seem to think the file name, is, the data! From what I can tell, that first argument to autocomplete can be either the data, or a URL. I guess autocomplete thinks that my data is in fact a URL.

Any ideas what I am doing wrong please?

1 Answer 1

1

I've cracked it.

The data I was retrieving was of course only a string. Hence autocomplete considering it a URL, and making the new request.

I can turn my JSON string into an array with:

var data_array = eval(data);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.