views:

186

answers:

3

Is it possible to use a stored procedure that returns multiple result sets in json format and process them as part of one request using ajax calls in jquery? In other words, I have a stored procedure that returns several result sets that are to be used with a series of select boxes that are all being filtered by the same criteria.

If any of the select boxes is chosen that value is then passed to the stored procedure and all the subsequent select box updates reflect only results that match the filtered criteria. I don't want to have to call the same sp multiple times to process the results and was trying not to create multiple queries, so I'm wondering if it's possible to store more than one json result in a single request and then store and process them on the client side.

A: 

Yes, JSON allows for nested objects and each object could contain one set of results. Without knowing how you are getting from the database to JSON I couldn't tell you exactly how to construct your JSON.

stimms
I'm calling a component on the server that is querying the data and then converting it into json format. If I were to call it with something like .getJSON() I would simply call the component by name and the json formatted data would be returned. However, right now I have seven different queries results being wrapped and returned so I'm trying to figure out the best approach. Thanks for the quick response.
Kevin
A: 

Using the json2.js library ( http://www.json.org/js.html ) you can turn JavaScript object into a string, and vice-versa. So

var obj = {'a':'1'}; //declare some js object
var s = json.stringify(obj); //turn it into a string for data transfer
obj = json.parse(s); //turn it back into a JavaScript object

The example above shows a very simple js object, but this can be substantially more complex, as you can embed arrays and other objects within objects

James Wiseman
Thanks, converting isn't the problem. I can get the data into json format, what I'm trying to do is call one sp that returns all the result sets I need and then figure out the best way to process them on the client side. Maybe the problem is I need one json formated file with multiple result sets within it so I can just reference each by name.
Kevin
A: 

Alternatively, stop parsing JSON and try using the jQuery taconite plugin. It easily handles multiple changes of all sorts. I absolutely love it.

Peter Rowell