我有这个功能:
// 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;
});
它正在工作,但我正在使用加载两次,我想这不是非常有效的方法来做到这一点。有没有办法加载一次数据然后从那些数据中选择你需要的东西?
答案 0 :(得分:1)
(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;
});
})();