【问题标题】:Best method of using jquery load and re-loading a script at the same time同时使用jquery加载和重新加载脚本的最佳方法
【发布时间】:2013-10-28 05:33:32
【问题描述】:

我有一个表,它使用 jquery 的 .load 函数在移动某些内容后重新加载表中的所有数据。

问题是当表格加载时,页面上的外部 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 的功能,这似乎不起作用。

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

【问题讨论】:

    标签: javascript jquery ajax


    【解决方案1】:

    尝试仅将 get() 与回调一起使用:

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

    【讨论】:

      猜你喜欢
      • 2012-03-02
      • 2013-06-23
      • 2012-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多