I need to update MySql table from Laravel view but when i submit the update the success message is displayed but nothing is updated inside MySql table or the view, the console log does not show any error. Here is code :
Controller :
public function reponse(Request $request)
{
$validation = Validator::make($request->all(), [
'reponse' => 'required',
]);
$error_array = array();
$success_output = '';
if ($validation->fails())
{
foreach ($validation->messages()->getMessages() as $field_name => $messages)
{
$error_array[] = $messages;
}
}
else
{
$student = Demo::find($request->get('ID'));
$student->reponse = $request->get('reponse');
$student->save();
$success_output = '<div class="alert alert-success">Data Updated</div>';
}
$output = array(
'error' => $error_array,
'success' => $success_output
);
echo json_encode($output);
}
View :
$('#student_form').on('submit', function(event){
event.preventDefault();
var form_data = $(this).serialize();
console.log($('#reponse').val());
$.ajax({
url:"",
method:"GET",
data:form_data,
dataType:"json",
success:function(data)
{
if(data.error.length > 0)
{
var error_html = '';
for(var count = 0; count < data.error.length; count++)
{
error_html += '<div class="alert alert-danger">'+data.error[count]+'</div>';
}
$('#form_output').html(error_html);
}
else
{
$('#form_output').html(data.success);
$('#student_form')[0].reset();
$('#req_table').DataTable().ajax.reload();
}
}
})
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire