javascript - jquery ajax data container -
i'm developing client-side application load quite lot of data via ajax , store somewhere in javascript models. in short, application has following elements:
- ajax calls: loading user list, loading financial data (user incomes , outcomes, loading chart data based on incomes/outcomes)
- the list of users loaded during initial page load (and doesn't change)
- financial data can retrieved chosen users given time period
- there dialog user checkbox list - after dialog submitted, financial data retrieved (via ajax) users
so there ajax calls once per entire page load , ajax calls called each time filters changed.
i've found out jquery provides .data() function binds data specific dom objects. but, can see, don't need bind data specific dom object, manage globally. there recommended approach, suggest?
for global data can consider global javascript object contains values. instance, declare globaldata:
var globaldata = {users : /*put user list here*/ }; then assign values global data object retrieved.
$.ajax(success:function(data){ globaldata.transactions = data; }); you assign data constrained specific ui elements using .data() function. instance if have section of page displays account lists use .data() function, such ajax request account list.
$.ajax(success:function(data){ $("#accountlist").data(data); });
Comments
Post a Comment