Is it possible to include the JSON once?

Kuba's Avatar

Kuba

18 Jan, 2011 10:16 AM

Hi,
at the begining - soryr for my english ;)
I've got big JSON file with tags - about 1000 entries. I include this file by:
`$("#tagInput").autoSuggest('autosuggest/data.php',{

          selectedItemProp: "name", 
          searchObjProps: "name", 
          minChars: 2, 
          asHtmlID: "tags"
        });`

And it is a problem - because JSON file with query string is includes many times (depends on typing speed) - i chose 6 tags and the script generates ~400kb
I try sometching like this:
`var data = $.getJSON('autosuggest/data.php'); $("#tagInput").autoSuggest(data,{

but it doesn't work ...
is it possible to include the JSON file not as many times as in the first example above - but only once per script ?
Thanks for help, and sorry for my bad english :),
Kuba

  1. 1 Posted by Kuba on 18 Jan, 2011 10:22 AM

    Kuba's Avatar

    some problems with formatting:
    first code:
    $("#tagInput").autoSuggest('autosuggest/data.php',{selectedItemProp: "name", searchObjProps: "name", minChars: 2, asHtmlID: "tags" });

    second code:
    var data = $.getJSON('autosuggest/data.php'); $("#tagInput").autoSuggest(data,{ selectedItemProp: "name", searchObjProps: "name", minChars: 2, asHtmlID: "tags" });

  2. 2 Posted by Odin Dutton on 17 Jun, 2011 11:36 PM

    Odin Dutton's Avatar

    Hey Kuba,

    I was having the same problem as you, ended up partly using your solution with $.getJSON, here is what I came up with. I'm sure you have it worked out by now but it might help someone else if they come across this problem.

    $.getJSON('/tags.json', function(data) {
      $('li#step_tag_list_input input').autoSuggest(data, {selectedItemProp: 'name', searchObjProps: 'name'});
    });
    

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac