1
我剛剛使用Ajax。我有一個Ruby應用程序,它使用Ajax請求從我的數據庫中刪除一個項目。刷新瀏覽器後,刪除僅在頁面上顯示。我究竟做錯了什麼?由於Ajax調用而導致的更改現在顯示在頁面中,除非我刷新瀏覽器
這裏是與阿賈克斯我再培訓局的文件稱
<script>
$(document).ready(function(){
$('input[type="checkbox"]').on("change", function() {
var hall_id = $(this).val();
$.ajax({
type:"GET",
url:"items/" +hall_id ,
dataType:"json",
data: {id: hall_id},
success:function(result){
alert(result);
}
})
});
});
</script>
<%= link_to "Logout", root_path %>
<h1>Hello <%= @user.first_name%> <%= @user.last_name%></h1>
<%= form_for @item do |f| %>
<%= f.label :to_do %>:
<%= f.text_field :to_do %><br />
<%= f.hidden_field :email, :value => @user.email%>
<%= f.submit %>
<% end %>
<% @items.each do |item|%>
<%if item.email == @user.email%>
<%= form_for @item do |f| %>
<%= f.check_box :to_do, {}, item.id %>
<%= item.to_do%><br />
<% end %>
<%end%>
<%end%>
這裏是我的控制器
class ItemsController < ApplicationController
def index
end
def new
end
def show
@items = Item.find(params[:id])
Item.destroy(params[:id])
puts @items.email
redirect_to :back
end
def create
@item = Item.create(to_do: params[:item][:to_do], email: params[:item][:email])
redirect_to :back
end
end