I have Datatable in which I am getting all the records from database, now I have rendered a feedback button for all the the records. On click of the Feedback button a modal popup window open with option to submit the feedback for particular id. Now as I have rendered Feedback button not sure how to insert the feedback for particular id using ajax. In my database there is Feedback column which have no values as of now, want to insert the value submitted to be inserted in database.
Here is my code how I have rendered Feedback button for all the records.
{
render:function(data, type, row){
return "<a href='#modal-lg5' data-toggle='modal' data-target='#modal-lg5' class='btn btn-warning btn-sm'> Feedback </a>"+
"<div class='modal fade' id='modal-lg5'>"+
"<div class='modal-dialog modal-lg'>"+
"<div class='modal-content'>"+
"<div class='modal-header'>"+
"<h4 class='modal-title'>Submit Feedback</h4>"+
"<button type='button' class='close' data-dismiss='modal' aria-label='Close'>"+
"<span aria-hidden='true'>×</span>"+
"</button>"+
"</div>"+
"<div class='modal-body'>"+
"<div class='row'>"+
"<div class='col'>"+
"<form id='contactForm'>"+
"<div class='form-group'>"+
"<label>Details:</label>"+
"<input type='text' name='title' class='form-control' placeholder='details' required=''>"+
"</div>"+
"</div>"+
"<button class='btn btn-success'>Submit Feedback</button>"+
"</div>"+
"</form>"+
"</div>"
}
}
This is how I have written the ajax
$("#contactForm").on('submit',function(e){
e.preventDefault();
var Feedback = $("input[name=title]").val();
var url = '{{ route('postinsert') }}';
$.ajax({
url:url,
method:'POST',
data:{
Feedback:Feedback
},
success:function(response){
if(response.success){
alert(response.message) //Message come from controller
}else{
alert("Error")
}
},
error:function(error){
console.log(error)
}
});
and this is my controller code:
public function ajaxRequestPost(Request $request)
{
\DB::table('memberdetails')->insert([
'Feedback' => $request->Feedback, //This Code coming from ajax request
]);
return response()->json(
[
'success' => true,
'message' => 'Data inserted successfully'
]
);
}
As I am working on this for the first time not sure how I can achieve my desired output, any help to resolve would be really great.