Answer the question
In order to leave comments, you need to log in
How to send data via AJAX in Rails?
Hello!
There is a page with products, each product has a "Details" link, and a data-id containing the product id is attached to each link.
I have an item_search_by_id(id) method that takes an item id and searches for all item information by id.
I don’t understand how I can pass data-id to the method and get a response. Tell me please
Answer the question
In order to leave comments, you need to log in
You must have a route created to receive data by ide, there must be a method in the controller, and then just an ajax request (coffeescript code):
item_id = $(element).data('id')
$.ajax
url:
type: 'get'
data: { 'item_id': item_id }
dataType: 'json'
success: (response) ->
...
error: (response) ->
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question