0
我有一个这种形式。Rails窗体助手 - 输入 - Ajax
<%= form_for @snitch, html: { class: "form-actions", method: 'delete' } do |form| %>
<span class="button-text"><%= link_to 'NO WAY!', home_base_url_or_default(root_path), rel: "modal:close" %></span>
<input type="submit" class="button button--modal delete-snitch" data-snitch-id="<% @snitch.token %>" value="Yes, delete it.">
<% end %>
正如您在第3行看到的那样有一种输入类型。我在它上面有这个属性data-snitch-id
我把它设置成了snitch令牌。我只是想知道,如果这是正确的,因为它回来未定义...
这是我的知识。
我使用它的Ajax调用
$(document).on('click','.delete-snitch', function(e) {
e.preventDefault();
var snitchID = $(this).attr('data-snitch-id');
$.ajax({
type: 'DELETE',
url: '/snitches/' + snitchID,
datatype: 'json'
success: function(){
$('#tr-for-snitch-' + snitchID).fadeOut
}
});
});
但它不工作,因为data-snitch-id
回来为未定义。