Answer the question
In order to leave comments, you need to log in
How to pass post ID on Ajax submit?
Good evening everyone. Tell me how you can pass the post id to the controller when sending ajax.
Can I do something through the route?
Here is AJAX
$('#recipe_comments').on('submit', function(e) {
e.preventDefault();
var text = $('.text').val();
$.ajax({
type: "POST",
url: '/add_comment',
data: {text:text},
success: function(param)
{
console.log(param);
},
error: function(msg){
console.log('error');
}
});
});
Route::get('/add_comment', '[email protected]');
Answer the question
In order to leave comments, you need to log in
Route::get('/add_comment/{id}', '[email protected]');
public function addCommend($id)
{
//$id - ваш id
}
$('#recipe_comments').on('submit', function(e) {
e.preventDefault();
var text = $('.text').val();
var id = 123;
$.ajax({
type: "POST",
url: '/add_comment',
data: {
'id': id,
'text':text
},
success: function(param)
{
console.log(param);
},
error: function(msg){
console.log('error');
}
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question