相关疑难解决方法(0)

在beforeSend上停止$ .ajax

我有这个jQuery ajax调用:

$.ajax({
    url : 'my_action',
    dataType: 'script',
    beforeSend : function(){
        if(1 == 1) //just an example
        {
            return false
        }
    },
    complete: function(){
        console.log('DONE');
    }
});
Run Code Online (Sandbox Code Playgroud)

我想在beforeSendif条件返回的情况下停止ajax调用true但返回false不会停止ajax调用.

我怎么能stop在ajax上调用beforeSend

=======更新=========

return false 也有效.

ajax jquery

41
推荐指数
4
解决办法
6万
查看次数

表单提交两次,原因是:remote => true

我的表单提交两次,经过双重检查后,由':remote => true'引起.我删除它,我的项目运作良好.谁能告诉我为什么?以及如何使用':remote => true'?

我的红宝石代码:

<%= form_tag(admin_product_group_product_scopes_path(@product_group), :remote => true, :id => 'new_product_group_form') do %>
    <%
    options =
    grouped_options_for_select(
    Scopes::Product::SCOPES.map do |group_name, scopes|
      [
        t(:name, :scope => [:product_scopes, :groups, group_name]),
        scopes.keys.map do |scope_name|
          [ t(:name, :scope => [:product_scopes, :scopes, scope_name]), scope_name]
        end
      ]
    end
    )
    %>
    <p>
      <label for="product_scope_name"><%= t('add_scope') %></label>
      <%= select_tag("product_scope[name]", options) %>
      <input type="submit" value="<%= t('add') %>" />
    </p>
  <% end %>
Run Code Online (Sandbox Code Playgroud)

浏览器中的最终html代码.

 <form accept-charset="UTF-8" action="/admin/product_groups/17/product_scopes" data-remote="true" id="new_product_group_form" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="?"><input name="authenticity_token" type="hidden" value="GocX/l4ZNgF/feKtzC8FuohebM2k5MuIHtdeGp2Oi0A="></div> …
Run Code Online (Sandbox Code Playgroud)

ruby forms post ruby-on-rails ruby-on-rails-3

20
推荐指数
2
解决办法
1万
查看次数

标签 统计

ajax ×1

forms ×1

jquery ×1

post ×1

ruby ×1

ruby-on-rails ×1

ruby-on-rails-3 ×1