SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
samy_666
Posts: 2Questions: 1Answers: 0
hey guys i have a problem the ajax request respons with this message (SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data)
i'm using the serverside and i have no idea why the json is invalid plz help
i'm using laravel and this is the code in the controller to return records from the database
public function gestionParticipant($id){
$participant = Participant::all()->whereIn('event_id',$id);
return DataTables::of($participant)
->addColumn('Adherent',function($participant){
return ''.$participant->participantAdherent->first_name.'';
})
->addColumn('Participant',function($participant){
return ''.$participant->nom_participant.' '.$participant->nom_participant.'';
})
->addColumn('Payeur',function($id){
$payeur = Payeur::all()->whereIn('event_id',$id);
return ''.$payeur->nom_payeur.' '.$payeur->prenom_payeur.'';
})
->addColumn('Montant',function(){
})
->addColumn('Presence',function(){
});
}
i'm trying to show the datatable in a bootstrap modal
javascript code in the view
$('#table').on('click','.showModal',function() {
var id = $(this).data('id');
$('#tableModal').DataTable({
"processing": true,
"serverSide": true,
"ajax": "/admin/evenment/event/participant/ajax_gestion_participant/"+id,
"columns":[
{"data":"Adherent"},
{"data":"Participant"},
{"data":"Payeur"},
{"data":null},
{"data":null},
]
});
$('#gestionModal').modal('show');
This discussion has been closed.
Answers
I'm not familiar with Laravel but are you returning the response as a JSON encoded string?
https://laravel.com/docs/5.8/responses#json-responses
You can use the steps in this technote to look at the response in the browser and use JSOPN Lint to validate the response. Let us know what you find.
Kevin
sorry i forgot to add the ->make(true) at the end