How to pass the attributes in ajax which can be accessed through params in the controller in ruby on rails?
up vote
0
down vote
favorite
My index.html.erb file looks like:
index.html.erb
...
<div class="panel-heading">
<h4 class="panel-title">
<li class="list-group-item">
Post --> <%= post.message %>
<%= link_to "Like", 'javascript:void(0)', class: "btn btn-default like-right-position like-btn"%>
<span class="like-right-position like-text">Likdfe</span>
</li>
<a class="btn btn-info pull-right" data-parent="#accordion1" data-toggle="collapse" href="#collapse-post-<%= post.id %>"> Comments</a>
</h4>
</div>
...
And my application.js file is:
$('.like-btn').click(function(){
$.ajax({
type: "POST",
url: "like_user_post_path",
data: "",
success: function(result){
$(".like-text").html(result);
}
});
});
I do not understand the concept of data attributes in html and how to pass it through ajax. Thanks in advance!!!
jquery ruby-on-rails ruby ajax
New contributor
add a comment |
up vote
0
down vote
favorite
My index.html.erb file looks like:
index.html.erb
...
<div class="panel-heading">
<h4 class="panel-title">
<li class="list-group-item">
Post --> <%= post.message %>
<%= link_to "Like", 'javascript:void(0)', class: "btn btn-default like-right-position like-btn"%>
<span class="like-right-position like-text">Likdfe</span>
</li>
<a class="btn btn-info pull-right" data-parent="#accordion1" data-toggle="collapse" href="#collapse-post-<%= post.id %>"> Comments</a>
</h4>
</div>
...
And my application.js file is:
$('.like-btn').click(function(){
$.ajax({
type: "POST",
url: "like_user_post_path",
data: "",
success: function(result){
$(".like-text").html(result);
}
});
});
I do not understand the concept of data attributes in html and how to pass it through ajax. Thanks in advance!!!
jquery ruby-on-rails ruby ajax
New contributor
Why do not you use data field inside ajax block ?
– ray
22 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My index.html.erb file looks like:
index.html.erb
...
<div class="panel-heading">
<h4 class="panel-title">
<li class="list-group-item">
Post --> <%= post.message %>
<%= link_to "Like", 'javascript:void(0)', class: "btn btn-default like-right-position like-btn"%>
<span class="like-right-position like-text">Likdfe</span>
</li>
<a class="btn btn-info pull-right" data-parent="#accordion1" data-toggle="collapse" href="#collapse-post-<%= post.id %>"> Comments</a>
</h4>
</div>
...
And my application.js file is:
$('.like-btn').click(function(){
$.ajax({
type: "POST",
url: "like_user_post_path",
data: "",
success: function(result){
$(".like-text").html(result);
}
});
});
I do not understand the concept of data attributes in html and how to pass it through ajax. Thanks in advance!!!
jquery ruby-on-rails ruby ajax
New contributor
My index.html.erb file looks like:
index.html.erb
...
<div class="panel-heading">
<h4 class="panel-title">
<li class="list-group-item">
Post --> <%= post.message %>
<%= link_to "Like", 'javascript:void(0)', class: "btn btn-default like-right-position like-btn"%>
<span class="like-right-position like-text">Likdfe</span>
</li>
<a class="btn btn-info pull-right" data-parent="#accordion1" data-toggle="collapse" href="#collapse-post-<%= post.id %>"> Comments</a>
</h4>
</div>
...
And my application.js file is:
$('.like-btn').click(function(){
$.ajax({
type: "POST",
url: "like_user_post_path",
data: "",
success: function(result){
$(".like-text").html(result);
}
});
});
I do not understand the concept of data attributes in html and how to pass it through ajax. Thanks in advance!!!
jquery ruby-on-rails ruby ajax
jquery ruby-on-rails ruby ajax
New contributor
New contributor
New contributor
asked 22 hours ago
Pujan Soni
83
83
New contributor
New contributor
Why do not you use data field inside ajax block ?
– ray
22 hours ago
add a comment |
Why do not you use data field inside ajax block ?
– ray
22 hours ago
Why do not you use data field inside ajax block ?
– ray
22 hours ago
Why do not you use data field inside ajax block ?
– ray
22 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
As per the description mentioned in the post, the data attrbutes are the ones which are sent as body for the following POST request via ajax.
$('.like-btn').click(function(){
$.ajax({
type: "POST",
url: "like_user_post_path",
data: {"field1": "value1", "field2": "value2"},
success: function(result){
$(".like-text").html(result);
}
});
});
Above is an example where the field1 and field2 specify the keys from which you will be parsing over the controller to fetch the corresponding values.
How can we set the same data attributes in the link_to tag?
– Pujan Soni
21 hours ago
link_to "abc", abc_path(@abc.id, param1: 'value1', param2: 'value2'), method: :post
– Rohan
21 hours ago
Thanks a lot!!! @Rohan
– Pujan Soni
20 hours ago
It would be great if you could mark it as a correct, if it was helpful so that others can benefit from the same.
– Rohan
19 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
As per the description mentioned in the post, the data attrbutes are the ones which are sent as body for the following POST request via ajax.
$('.like-btn').click(function(){
$.ajax({
type: "POST",
url: "like_user_post_path",
data: {"field1": "value1", "field2": "value2"},
success: function(result){
$(".like-text").html(result);
}
});
});
Above is an example where the field1 and field2 specify the keys from which you will be parsing over the controller to fetch the corresponding values.
How can we set the same data attributes in the link_to tag?
– Pujan Soni
21 hours ago
link_to "abc", abc_path(@abc.id, param1: 'value1', param2: 'value2'), method: :post
– Rohan
21 hours ago
Thanks a lot!!! @Rohan
– Pujan Soni
20 hours ago
It would be great if you could mark it as a correct, if it was helpful so that others can benefit from the same.
– Rohan
19 hours ago
add a comment |
up vote
0
down vote
accepted
As per the description mentioned in the post, the data attrbutes are the ones which are sent as body for the following POST request via ajax.
$('.like-btn').click(function(){
$.ajax({
type: "POST",
url: "like_user_post_path",
data: {"field1": "value1", "field2": "value2"},
success: function(result){
$(".like-text").html(result);
}
});
});
Above is an example where the field1 and field2 specify the keys from which you will be parsing over the controller to fetch the corresponding values.
How can we set the same data attributes in the link_to tag?
– Pujan Soni
21 hours ago
link_to "abc", abc_path(@abc.id, param1: 'value1', param2: 'value2'), method: :post
– Rohan
21 hours ago
Thanks a lot!!! @Rohan
– Pujan Soni
20 hours ago
It would be great if you could mark it as a correct, if it was helpful so that others can benefit from the same.
– Rohan
19 hours ago
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
As per the description mentioned in the post, the data attrbutes are the ones which are sent as body for the following POST request via ajax.
$('.like-btn').click(function(){
$.ajax({
type: "POST",
url: "like_user_post_path",
data: {"field1": "value1", "field2": "value2"},
success: function(result){
$(".like-text").html(result);
}
});
});
Above is an example where the field1 and field2 specify the keys from which you will be parsing over the controller to fetch the corresponding values.
As per the description mentioned in the post, the data attrbutes are the ones which are sent as body for the following POST request via ajax.
$('.like-btn').click(function(){
$.ajax({
type: "POST",
url: "like_user_post_path",
data: {"field1": "value1", "field2": "value2"},
success: function(result){
$(".like-text").html(result);
}
});
});
Above is an example where the field1 and field2 specify the keys from which you will be parsing over the controller to fetch the corresponding values.
answered 22 hours ago
Rohan
9791311
9791311
How can we set the same data attributes in the link_to tag?
– Pujan Soni
21 hours ago
link_to "abc", abc_path(@abc.id, param1: 'value1', param2: 'value2'), method: :post
– Rohan
21 hours ago
Thanks a lot!!! @Rohan
– Pujan Soni
20 hours ago
It would be great if you could mark it as a correct, if it was helpful so that others can benefit from the same.
– Rohan
19 hours ago
add a comment |
How can we set the same data attributes in the link_to tag?
– Pujan Soni
21 hours ago
link_to "abc", abc_path(@abc.id, param1: 'value1', param2: 'value2'), method: :post
– Rohan
21 hours ago
Thanks a lot!!! @Rohan
– Pujan Soni
20 hours ago
It would be great if you could mark it as a correct, if it was helpful so that others can benefit from the same.
– Rohan
19 hours ago
How can we set the same data attributes in the link_to tag?
– Pujan Soni
21 hours ago
How can we set the same data attributes in the link_to tag?
– Pujan Soni
21 hours ago
link_to "abc", abc_path(@abc.id, param1: 'value1', param2: 'value2'), method: :post
– Rohan
21 hours ago
link_to "abc", abc_path(@abc.id, param1: 'value1', param2: 'value2'), method: :post
– Rohan
21 hours ago
Thanks a lot!!! @Rohan
– Pujan Soni
20 hours ago
Thanks a lot!!! @Rohan
– Pujan Soni
20 hours ago
It would be great if you could mark it as a correct, if it was helpful so that others can benefit from the same.
– Rohan
19 hours ago
It would be great if you could mark it as a correct, if it was helpful so that others can benefit from the same.
– Rohan
19 hours ago
add a comment |
Pujan Soni is a new contributor. Be nice, and check out our Code of Conduct.
Pujan Soni is a new contributor. Be nice, and check out our Code of Conduct.
Pujan Soni is a new contributor. Be nice, and check out our Code of Conduct.
Pujan Soni is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372105%2fhow-to-pass-the-attributes-in-ajax-which-can-be-accessed-through-params-in-the-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why do not you use data field inside ajax block ?
– ray
22 hours ago