Drupal:在 Drupal 中加载 AJAX 内容
我最近被告知要使用面板通过 Drupal 将内容动态加载到不同的部分。然而,我刚刚意识到有一种简单的方法可以做到这一点,我已将此 jQuery 代码添加到所有菜单项中:
$('.menu a').click(function(){
$('#content').load($(this).attr('href') + " #content");
return false; //to avoid refresh
});
通过这种方式,我可以轻松地从任何链接更新任何块,而无需使用面板。
这种方法好吗? 您是否还认为面板不需要简单地将 html 动态加载到网站部分?
谢谢
I've recently been told to use Panels to dynamically load content into different sections with Drupal. However, I've just realized that there is an easy way to do it, I've added this jQuery code to all menu items:
$('.menu a').click(function(){
$('#content').load($(this).attr('href') + " #content");
return false; //to avoid refresh
});
In this way I can easily update anyblock from any link without having to use Panels.
Is this approach a good one ?
Do you also think Panels is not necessary to simply load html into website sections dynamically ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
面板的主要用途是在没有页面加载的情况下不加载内容。它主要用于
您当前的脚本可以工作,但目前的形式有点粗糙。 Fx,如果用户点击多次会发生什么。如果您想动态更新内容,您应该只更改需要更改的部分,而不是加载/更改整个页面。那么您不妨只加载新页面。我想这就是面板可以帮助您的地方,但我还没有尝试过使用这样的面板。
Panels main usage, is not loading content without page loads. It's primarily used
Your current script will work, but it's a bit crude in it's current form. Fx, what will happen if a user clicks several times. If you want to dynamically update your content, you should only change the parts that needs changing instead of loading/changing the whole page. Then you might as well just load the new page instead. I guess this is where Panels can help you, but I haven't tried using Panels like that.