我有这个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 也有效.
我的表单提交两次,经过双重检查后,由':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)