Hello all, I'm a newbie to jQuery and I need a sanity check.  I'm
trying to use the 'data' function of jquery to save some data between
redrawing div's.  Even though I can find the cached data using
Firebug, in some situations I can't retrieve the data.  Here is a
minimalistic example:

function fillFields() {
   var field = $("#contentDiv").data("field1");
   $("INPUT[name=field1]").val(field);
}

function getData() {
   var app_id = $("INPUT[name=app_id]").val();
   $.get(myUrl, { cmd: RD, app_id: app_id }, function(data) {
      $("#contentDIV").data("field1", data);
      fillFields();
   });
}

When a search field on the page is filled in and a button is clicked,
"getData()" is called.  With Firebug I can find "field1" in the cache;
so I know it's working.  But "fillFields()" does not fill the input
element.  If I move the contents of "fillFields()" into the
"$.get...function(data)" function, it then works.  So I put a link on
the page that calls "fillFields()" directly when clicked.  The
"fillFields()" function works as expected -- now it CAN see the cached
data.

Is there some kind of Scope or Context issue of which I am unaware?
Shouldn't I be able to call the "fillFields()" function from within
the "getData()" function as illustrated above?  I have to be missing
some basic understanding of jQuery/javascript.

Thank you.

Reply via email to