我想通过 AJAX 提交表单。当我提交表单时,它应该发送一个 ajax 并淡入 id 为 stepTwo 的 div,并淡出当前 div。我使用的是 jQuery 1.8.0,当我提交时,我的控制台中出现此错误。
NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindow.getComputedStyle]
[Break On This Error]
...=[]),o&&(e=" "+e);while(e){k=!1;if(j=B.exec(e))e=e.slice(j[0].length),k=d.push({...
这是我的 HTML:
<div id="stepOne">
<%= form_for @program do |f| %>
<div>
<label for="exerciseName">Title For Your Program</label>
<%= f.text_field :title, :name => "exerciseName", :required => "required", :maxlength => "40" %>
</div>
<div>
<label for="exerciseName">Detailed Info For Your Program</label>
<%= f.text_area :details %>
</div>
<%= f.submit "Next Step", :class => "exbuttons button-small red rounded3", :id =>"stepOneButton" %>
<% end %>
</div>
这是我的控制器
# POST /programs # POST /programs.json def create @program = Program.new(params[:progeram]) @program.user_id = current_user.id
respond_to do |format|
if @program.save
if request.xhr?
render @program
else
redirect_to @program
end
else
if request.xhr?
render @program
else
flash[:error] = "Program could not be added"
redirect_to new
end
end
end
end
这是我的 Javascript 文件
function stepOne(){
$('#new_program').submit(function(event){
event.preventDefault();
var f = $(this);
f.find('input[type="submit"]').attr("disabled", true);
$.ajax({
type: f.attr("method"),
url: f.attr("action"),
data: f.serialize(),
complete: function(){
f.find('input[type="submit"]').attr("disabled", false);
},
success : function(data){
console.log(data);
$(this).fadeOut();
$('#stepTwo').delay(400).fadeIn();
},
error : function(xhr, status){
console.log(status);
}
});
});
}