简体   繁体   English

将AJAX加载程序附加到单个链接上的菜单/导航栏

[英]Appending AJAX loader to menu/nav bar on individual links

I'm using the following theme for our site: http://themes.vivantdesigns.com/vpad/#dashboard.html 我在我们的网站上使用了以下主题: http : //themes.vivantdesigns.com/vpad/#dashboard.html

I want an ajax loader to show NEXT to the link/tab, when a user clicks a link within the drilldown menu on the left. 我希望ajax加载器在用户单击左侧的向下钻取菜单内的链接时在链接/选项卡上显示NEXT。 As you can see from the link, content is dynamically loaded within a: 从链接可以看到,内容在以下位置动态加载:

<section id="main-section">Pagename.html loaded here</section>

So basically, I want the ajax loader to show to the right of the menu links and disappear when the dynamic content loads. 因此,基本上,我希望ajax加载器显示在菜单链接的右侧,并在动态内容加载时消失。 It will be hard to see this pause on the demo link, but heavier database queries will cause it to sit there a moment, and slower connections of course. 很难在演示链接上看到这种暂停,但是繁重的数据库查询将使其停滞片刻,并且连接速度当然会变慢。

Any immediate help is appreciated very much. 非常感谢任何即时帮助。

I've tried show/hide onClick methods, hiding class on document ready, and nothing seems to work cleanly. 我试过显示/隐藏onClick方法,在文档上准备好隐藏类,似乎没有任何工作正常。

Okay, after a lot of screwing around trying to find where the ajax was happening, I think I've worked it out (little familiarity with jQuery/never heard of hashchange or bbq before), so give this a shot. 好吧,在尝试查找ajax发生了很多麻烦之后,我我已经解决了这个问题(对jQuery不太熟悉/之前从未听说过hashchange或bbq),因此请尝试一下。

Assuming you have access to it, the page you referenced is including a JavaScript file called global.js. 假设您有权访问它,那么您引用的页面包括一个名为global.js的JavaScript文件。

Add an initially hidden "loading" image/div/whatever next to each menu item, with an id set similarly to the menu item's name eg id="mediaLoading". 在每个菜单项旁边添加一个初始隐藏的“正在加载”图像/ div /所有内容,其ID的设置类似于菜单项的名称,例如id =“ mediaLoading”。

Open global.js and head down to line 117: 打开global.js并转到第117行:

$('#'+id).length && $('#'+id).remove();

After this line the ajax call is made, so add the code to show the ajax loader, eg 在此行之后,进行了ajax调用,因此添加代码以显示ajax加载器,例如

var loaderId = h.replace(/^\#/, "") + "Loading";
document.getElementById(loaderId).style.display = 'block'; 
//or $("#" + loaderId).show() or whatever you would use in jQuery

Finally, to re-hide it, add similar code into the inline 'complete' function (which would now be around line 127): 最后,要重新隐藏它,请将类似的代码添加到内联的“ complete”函数中(现在大约在第127行):

complete: function(jqXHR, textStatus) { 
    document.getElementById(loaderId).style.display = 'none';
}

Hope that solves it. 希望能解决。 It was difficult to test locally. 很难在本地进行测试。

Keep in mind that since the file's called "global," that obviously might impact a bunch of other pages, so you may want to use null-checks for the loader or a separate file... 请记住,由于文件被称为“全局”文件,因此显然可能会影响其他页面,因此您可能需要对加载程序或单独的文件使用null检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM