JQuery function preventing Rails remote call

给你一囗甜甜゛ 提交于 2019-12-12 03:45:17

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/11580866/jquery-function-preventing-rails-remote-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!