javascript - JQuery - reuse data after load -
i have function:
// ajax messages showing show_msg.on('click', function(e){ var $this = $(this), url = $this.attr('href'), url_info = url + ' .basic_info > *', url_msg = url + ' .contact_messages > *'; basic_info.slideup('fast', function(){ basic_info.empty().load(url_info, function(){ basic_info.slidedown('fast'); }); }); contact_messages.slideup('fast', function(){ contact_messages.empty().load(url_msg, function(){ contact_messages.slidedown('fast'); }); }); return false; });
it working, using load 2 times, , guess not effective way this. there way load data once , select need data?
you do:
(function(){ var basicinfoloaded = false, contactmessageloaded = false; // ajax messages showing show_msg.on('click', function(e){ var $this = $(this), url = $this.attr('href'), url_info = url + ' .basic_info > *', url_msg = url + ' .contact_messages > *'; basic_info.slideup('fast', function(){ if(basicinfoloaded) basic_info.slidedown('fast'); else{ basicinfoloaded = true; basic_info.empty().load(url_info, function(){ basic_info.slidedown('fast'); }); } }); contact_messages.slideup('fast', function(){ if(contactmessageloaded) contact_messages.slidedown('fast'); else{ contactmessageloaded = true; contact_messages.empty().load(url_msg, function(){ contact_messages.slidedown('fast'); }); } }); return false; }); })();