views:

160

answers:

4

I'm buiding an HTML/jQuery site where almost all the content comes from remote JSON data. I'm having trouble coming up with a good way to store and access the data in the future (scope-wise).

Currently, I've written a jQuery plugin that gets the JSONP data when the site loads. But I have other functions and jQuery plugins that need to access this data.

Where should this data be stored so other functions and plugins can access it?

Should it be a global variable?

If it matters, this site will only run on the iPad and the back-end of the site is in Rails.

A: 

Dojo has it.

If you do not have the constraint of using jquery, then maybe you can investigate it.

http://ajaxian.com/archives/dojostorage-offline-access-and-permanent-client-side-storage

Alternately, you could also probably just store it in an array that other plugins / functions can access it.

rmk
+1  A: 

If there's a manageable amount of JSON data you can access it through global variables. Preferably just one or two global objects with nested properties.

Developing a web page is not like developing a library I think a few globals are acceptable

Alexandre Jasmin
+4  A: 

I would suggest you investigate HTML5 persistant storage which is supported on Safari and Mobile Safari as a SQL Lite DB. If you decide not to go down that route I would opt for $().data() over a global variable in JavaScript.

kim3er
Thanks for the info. $().data() appears to attach the data to a DOM element. Would you suggest I just attach it to the document or body?
Callmeed
Given that you'll be potentially accessing this data from anywhere in the page, I'd probably attach to document, but I don't think it makes a great deal of difference. Glad I could help.
kim3er
+1  A: 

To store data between requests, you can use HTML5 Storage API. Otherwise just pass around the variable (reference) holding the data.

jholster