I'm trying to send ajax request in laravel 5.1. but i can't get ajax request. it always HTTP request.
I have a html form
<form role="form" method="POST" action="/admin/save-drug" id="add_drug">
<label for="drugs_name">Drug Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="drugs_name" id="drugs_name">
<label for="drugs_name">Drug Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="drugs_name" id="drugs_name">
<button type="submit" id="save_drug" class="btn btn-default waves-effect waves-light btn-md">
</form>
And i use ajax
$(document).ready(function(){
$('#add_drug').submit(function (){
$.ajax({
url: './admin/save-drug',
type: 'POST',
data : { 'drugs_name':$('input[name=drugs_name]').val()},
success: function(data){
alert(data)
}
});
});
});
My Controller
public function saveDrug(Request $request){
if($request->ajax()){
return "AJAX";
}else{
return "HTTP";
}
}
It alwayes return "HTTP" what's wrong with my code???
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire