jQuery功能防止Rails远程调用 [英] JQuery function preventing Rails remote call
问题描述
我的页面上有一个链接,该链接对passcheck_path
进行AJAX远程调用,其周围的p
标签提供了激活覆盖整个页面的JQuery模式框的功能.
<p class="right blackout">
<%= link_to "blank screen", passcheck_path, :remote => true %>
</p>
JS如下:
$().ready( function() {
$('.blackoutwindow').jqm({
modal: true,
trigger: '.blackout',
overlay: 100
});
});
当我单击链接时,将显示模式,但根本不会发生远程调用.但是,当我删除p
标记时,远程调用可以正常工作(但显然不会触发模式).我真的不知道为什么会这样,但是我认为javascript覆盖了某些东西?
非常感谢您的帮助.
jqModal插件您可以取消绑定链接上定义的所有单击处理程序,也可以取消绑定.
因此,您要么将插件切换到另一种或 jqueryui模态对话框,因为jqModal似乎已经过时了,或者您可以通过调用来实现工作循环远程通过jqModal的onShow回调:
$('.blackoutwindow').jqm({
modal: true,
onShow: function() {
$.get($(this).attr('href')); // DIY Implementation of the remote call
},
trigger: '.blackout',
overlay: 100
});
I have a link on my page which makes an AJAX remote call to passcheck_path
and the p
tags around it provide the function of activating a JQuery modal box which covers the entire page.
<p class="right blackout">
<%= link_to "blank screen", passcheck_path, :remote => true %>
</p>
The JS is as follows:
$().ready( function() {
$('.blackoutwindow').jqm({
modal: true,
trigger: '.blackout',
overlay: 100
});
});
When I click the link, the modal appears, but the remote call doesn't happen at all. However when I remove the p
tags, the remote call works perfectly (but obviously the modal doesn't trigger). I really have no idea why it's behaving like this but I assume the javascript is overriding something?
Your help would be greatly appreciated.
The jqModal plugin you use unbinds all the click handlers defined on your link, also the ones by rails.
So either you switch plugins to another one or jqueryui modal dialogs because jqModal seems quite outdated, or you can implement a workround by calling remotely with the onShow callback of jqModal:
$('.blackoutwindow').jqm({
modal: true,
onShow: function() {
$.get($(this).attr('href')); // DIY Implementation of the remote call
},
trigger: '.blackout',
overlay: 100
});
Have a look at this fiddle to see the problem and the solution
这篇关于jQuery功能防止Rails远程调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!