本文介绍了Rails UJS:使用“ajax:before"防止事件传播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用 rails/jquery 时 ajax:before 的工作方式感到困惑-ujs.

I am confused by how ajax:before works when using rails/jquery-ujs.

  1. 它是否等待 ajax:before 中的任何给定函数完成后再继续?

  1. Does it wait for any given function in the ajax:before to complete before proceeding?

如果在某些条件下失败,我如何完全取消 jQuery 中的事件?(我似乎没有指向该事件的指针)

How do I completely cancel the event in jQuery if it fails some condition? (I do not seem to have a pointer to the event)

--

更新:我试过这个,它通常有效,但现在不行.=|

Update: I tried this, which normally works, but not now. =|

.bind('ajax:before', function(evt){
    evt.stopImmediatePropagation();
   } )
 //also tried preventDefault, stopPropagation, etc

推荐答案

我回答了我自己的问题.ajax:before 中的 "return false" 将取消操作

I answered my own question. "return false" in the ajax:before will cancel the action

这篇关于Rails UJS:使用“ajax:before"防止事件传播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 09:19