2013-10-28 36 views
0

我有一个表,它使用jquery的.load函数来重新加载移动后的表中的所有数据。同时使用jquery加载和重新加载脚本的最佳方法

问题是,当表加载时,页面上的外部JavaScript文件不再在表中使用。

要自己解决这个问题,我已经开始使用jQuery的.getScript。这有效(有时),但效果不佳。我认为脚本需要很长时间才能加载,而表格会立即加载,导致脚本有时会变得混乱。

我也尝试过使用getScript后仍然不能正常工作的函数。

这是我使用目前

$(function() { 
     $("#sortable").sortable({ 
      update: function(event, ui) { 
       serial = $('#sortable').sortable('serialize'); 
       $.ajax({ 
       url: "./menu-controller.php", 
       type: "post", 
       data: serial, 
       success: function() { 
        $.getScript("./menu-admin.js"); 
        $("#sortable").load("./menu-manager.php #menu-table"); 
      }, 
       error: function(){ 
        alert("A problem occurred when moving this menu item. Please try again or contact support."); 
       } 
       }); 
      }, 
     handle:'.move-item', 
     connectWith:'#menu-table', 
     placeholder: "highlight", 
     containment: "parent", 
     revert: true, 
     tolerance: "pointer", 
     items: 'tbody > *' 
     }); 
    }); 

具体是什么,我们看的.sortable更新的“成功”。有没有更好的解决方案呢?

我的最终目标是在表开始加载之前让脚本完全加载。再次,我已经尝试过使用getScript的函数,但这似乎不起作用。

我感谢您提供的任何建议,提示或解决方案。

回答

1

尝试使用的get()只有一个回调这样:

$.get('http://ajax.googleapis.com/ajax/libs/ext-core/3.1.0/ext-core.js', function(response){ 
    // Start table 
}); 
+0

使用不用彷徨似乎是一个好一点,谢谢! –