I'm working on a page that has a form that is dynamically generated
using jQuery.  The form isn't built in one pass but progressively
based on user actions. Prior to submit the form may contain dozens of
select menus with varying option content.

The problem is that the select menu options contain values that are
stored in database. Those values can change, therefore it isn't safe
to hard code the menu options in jquery code.

I realize that I could make an AJAX call each time I need to build a
menu, but that will slow down the form generation. It is safe to say
that the values won't change during a user's session though. What I
would like to do is cache the various menu values when the page loads,
but I'm not sure the best way to do this?

Is it possible to perform a $.get() and store the result into a global
variable? I've tried something like this but it doesn't work.

                var foo = '';
                $.get("options.php", function(data){
                        foo = data; // try to store data into foo
                });

Optionally I suppose I could do something like this ...

                $.get("options.php", function(data){
                        $('body').append("<p style=\"display:none\" 
id=\"footext\">" +
data + "</p>"); // store data in a hidden page element
                });

and access get the value via $("#footext").text() everytime I need it,
but would prefer to use a variable.

Reply via email to