Javascript 如何使用JQuery缓存加载的html

Javascript 如何使用JQuery缓存加载的html,javascript,jquery,html,Javascript,Jquery,Html,我有一个Javascript函数,可以从服务器加载一些html: function addPerson(){ var p = $('<div>').load('data/person.php',function(){ //set click and key actions $('#element').append($(this)); }); return p; } 但是loadPerson从不填写任何信息。我在firean

我有一个Javascript函数,可以从服务器加载一些html:

function addPerson(){
    var p = $('<div>').load('data/person.php',function(){
        //set click and key actions

        $('#element').append($(this));
    });

    return p;
}
但是loadPerson从不填写任何信息。我在fireant中调试并意识到ep的值始终是一个空div,这使我意识到元素在异步查询完成之前被缓存。你知道如何返回完全加载的元素吗

另外,我需要两种功能

编辑:

我也曾尝试过,但运气不佳:

function addPerson(){
    var p;
    $('<div>').load('data/person.php',function(){
        //set click and key actions

        $('#element').append($(this));
        p = $(this);
    });

    return p;
}
函数addPerson(){
var-p;
$('').load('data/person.php',function(){
//设置单击和键操作
$('#元素')。追加($(this));
p=$(本);
});
返回p;
}

以下是我在项目中使用的模式

代码:

(function($) {
   var foo = {
       init: function() {
           this.someObject = null;
           this.cache();
           return this; // to allow chaining
       },
       cache: function() {
          this.someObject = $(".someClass");
       }
   };

   window.load = foo.init();
})(jQuery);

因为这是一个异步调用!Load在尝试查找尚未加载的元素后激发。使用回调!我想我正在这么做,看看jquery文档中的承诺,我想我们讨论的是不同的加载函数。我要问的是如何将html内容加载到服务器上的文件中……加载到缓存中的内容是否重要?
(function($) {
   var foo = {
       init: function() {
           this.someObject = null;
           this.cache();
           return this; // to allow chaining
       },
       cache: function() {
          this.someObject = $(".someClass");
       }
   };

   window.load = foo.init();
})(jQuery);