0
Rails 4アプリケーションにAjaxリクエストがありますが、ボタンをクリックするとデータがDBに追加されません。私は何が欠けていますか?ページはキャッシュされているので、単にlink_toまたはbutton_toを追加することはできません。前もって感謝します。Ajax/JS - DBに追加されていません
JSファイル:
$(document).ready(function() {
$(".listcollect").on("click", function(event) {
event.preventDefault();
var listID = this.id;
$.ajax({
method: "GET",
url: "/listing_collections/:id/listcollect",
success: function(result) {
var arrLen = result.length
for (var i = 0; i < arrLen; i++) {
var $li = $("<li></li>");
var $a = $('<a class="listing-collection-item"></a>');
$a.attr("href", "/listings/" + listID + "/add_to_collection?listing=" + listID + "$amp;listing_collection_id=" + result[i]["id"] + "&listing_id=" + listID)
$a.text(result[i]["name"])
$li.append($a)
$(this).next().append($li)
}
}.bind(this)
})
});
$("ul.dropdown-menu").on("click", ".listing-collection-item", function(e) {
var url = $(this).attr("href");
alert("The listing was added to the collection!");
return false;
});
});
マイhtml.erbファイル:私の知る限り、あなたのスクリプトに任意のデータを送信していない言うことができるように
<div class="btn-group listcollect-wrapper">
<button class="listcollect button btn-blue-white btn-2x dropdown-toggle" data-toggle='dropdown' type="button" id=<%= listing.id %>>Add to Listing Collection <span class="caret"></span></button>
<ul class='dropdown-menu'>
</ul>
</div>