我有一个自定义插件,最初是通过将哈希标记和页面ID附加到URL来通过Ajax将html内容加载到页面中的。

对于这种复杂程度,我是一个新手,我想“撤消”此功能,因此该插件可以在不使用Router功能的情况下进行初始化。我已经看了这几天了,很迷路...

整个插件似乎已通过此功能初始化。有关如何“关闭”此功能的任何提示或建议,因此仍在不将#附加到URL的情况下对代码进行初始化也将不胜感激。

$(function() {

var connections = [],
    IEversion = detectIE(),
    killConnections = null,
    node = null,
    randomBehaviour,
    rootIndex = 1,
    silentRoute = null;

// Splash.
var splash = {
    init: function() {
        $('#splash').addClass('active');
        $('.node.splash').draggable({
            containment: 'parent',
            drag: function() {
                if(!splash.destroyed) {
                    $('.node.splash').addClass('dragging');
                    splash.destroy('drag');
                    splash.destroyed = true;
                }
            },
            scroll: false,
            disabled: false
        });
        setTimeout(function() {
            if($('.arrow').is(':visible')) {
                splash.destroy();
            }
        }, 4000);
    },
    destroy: function(event) {
        if(event === 'drag') {
            $('.arrow').hide();
        } else {
            $('.arrow').fadeOut(500);
        }
        $('#splash-wrapper p, .node.splash').fadeOut(500);
        setTimeout(function() {
            $('#splash').remove();
            nody.init();
        }, 500);
    },
    destroyed: false
};

// Router.
var routes = {
    '/': function() {
        if(!splash.destroyed) {
            splash.init();
        }else {
            nody.unloadMenu();
        }
    }
};

var router = Router(routes);

router.configure({
    strict: false,
    before: function() {
        if(silentRoute) {
            silentRoute = false;
            return false;
        }
    }
}).init('/');

});

最佳答案

一个简单的答案-

$.mobile.ajaxEnabled = false;


使用jQuery Mobile。

详细信息为here

如果您想使用jQuery,则没有直接的方法。

因此,您应该像这样使用全局变量来做到这一点-



var is_ajax_enabled = true;

$(document).ready(function()
{
    ...................
    ...................
    $("selector").click(function()
    {
        ...................
        //before AJAX call, just do a checking like it-
        if(is_ajax_enabled())
        {
          //make your AJAX call here
          $.ajax({url: "demo_test.txt", success: function(result)
          {
            $("#div1").html(result);
          }});
        }
        ...................
    });
    ...................
    ...................
});

function disable_ajax()
{
    is_ajax_enabled=false;
}

function enable_ajax()
{
    is_ajax_enabled=true;
}

function is_ajax_enabled()
{
    return is_ajax_enabled;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>





更新-

如果您一次只希望有一个请求并为该请求排队,则可以像下面这样尝试jQuery-Ajax-Singleton-

$.ajax(options || {})

关于javascript - 通过功能禁用AJAX内容加载,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36002707/

10-12 00:07
查看更多