Using Jquery to get JSON objects from local file.

Posted by ThoughtCrhyme on Stack Overflow See other posts from Stack Overflow or by ThoughtCrhyme
Published on 2010-05-08T00:27:06Z Indexed on 2010/05/08 0:38 UTC
Read the original article Hit count: 660

Filed under:
|
|

I'm trying to get a list of JSON objects (products) from a local file using Jquery and store all the objects in a single array called allItems. The file is co-located in the same directory as the code, and it's called "allItems.json". Here's how I'm doing it now:

function getAllSupportedItems(){
    var allItems = new Array();
    $.getJSON("allItems.json",
         function(data){
             $.each(data.items, 
             function(item){
                 allItems.push(item);
             });
         });
    return allItems;
}

Based on this example: http://api.jquery.com/jQuery.getJSON/

© Stack Overflow or respective owner

Related posts about JSON

Related posts about jQuery