I just got introduced to JQuery and using JSON data yesterday. I'm wondering if I'm properly and efficiently using them because it's really not making sense.
With what I have to work with, It seems like I'm grabbing entire databases worth of data EVERY time someone makes a request and processing it in the browser. That doesn't seem remotely efficient, why can't I just ask for the piece of data I need by querying the JSON file for items that match certain criteria, allowing the server to do most of the work?
We have a site using ASP.NET (aspx files using C#, that's about all I know).
We have numerous databases that we can access as either JSON or XML.
The many databases are linked together with ID's, I need to be able to search each database for a specific ID and pull out all the specific information related to that ID and throw it into a multidimensional array. Can I do this without grabbing every single DB we have, loading it into the browser and manipulating it with JavaScript? Some DB's are over 2MB in size, I feel like it could get sluggish quickly.
Here's the code I'm currently using, part of it anyway. I'm not happy with this either, why do I have to chain my $.getJSON requests together with functions? If I don't, the array's don't get built because the $.getJSON happens simultaneously as any outside methods I use to manipulate the array.
(JQuery 1.5.1)
- var elem1Array = new Array();
- var elem2Array = new Array();
- function assessElem1()
- {
- $.getJSON('http://XXX.XXX.XXX.svc/TableName1?$format=json&$callback=?',
- function (response)
- {
-
- $.each(response.d, function (index, value)
- {
- elem1Array.push(value.ID);
- //alert(newArray[index]);
- });
- assessElem2(elem1Array);
- }
- );
- }
-
- function assessElem2(Array1)
- {
- $.getJSON('http://XXX.XXX.XXX.svc/TableName2?$format=json&$callback=?',
- function (response)
- {
-
- $.each(response.d, function (index, value)
- {
- elem2Array.push(value.ID);
- //alert(newArray[index]);
- });
- groupObjects(elem1Array,elem2Array);
- }
- );
-
- }
- function groupObject(array1,array2)
- {
- // This function will search for matching ID #'s and create a
- // multimensional array with the parent ID and the ID's of the
- // matching child elements.
- }
It's possible for me to create and use a .aspx file instead but I don't know much about C# or if it would be any more efficient than JQuery.