I try to insert data in database with Ajax, but it doesn't work Error: POST http://127.0.0.1:8000/%7B%7Broute('achats.store')%7D%7D 405 (Method Not Allowed) Controller:
$achat = new achat();
$achat->libellé=$request->input('libll');
$achat->date_achat=$request->input('achatDate');
$achat->montant_total=$request->input('montant');
$achat->Agent=Auth::user()->id;
$achat->fournisseur=$request->get('frn');
if($request->file('bon')){
$bon=$request->file('bon');
$achat->bon=$bon->getClientOriginalName();
$bon->move('bon',$bon->getClientOriginalName());
}
$achat->save();
return response()->json([
'status'=>true,
'msg'=>'Sauvegardé avec succès'
]);
return response()->json([
'status'=>false,
'msg'=>'Le sauvegarde a échoué veuillez réessayer'
]);
Code js:
$("#btn_submit").click(function(e){
e.preventDefault();
$.ajax({
type:'POST',
url:"",
data:$("#frm_add").serialize(),
success: function(date){
},error : function(reject){
}
})
})
Via Active questions tagged javascript - Stack Overflow https://ift.tt/ajEu7kn
Comments
Post a Comment