Sorry for my later answer ... I tried some yhings. I have this : Form :
<form method="POST" id="inner" class="ajax" action="{{ route('items.indication.insert') }}" accept-charset="UTF-8">
<div class="form-group {{ ($errors->has('indication_name')) ? 'has-error' : '' }}">
<input class="form-control" placeholder="indication_name" name="indication_name" type="text" value="{{ Input::old('indication_name') }}">
</div>
<input name="_token" value="{{ csrf_token() }}" type="hidden">
<button class="btn btn-primary sendbttn" value="{{ trans('site/buttons.create') }}" type="submit">Send</button>
</form>
Javascript
<script>
$(document).ready(function(){
$('#innerbutton').click(function(e) {
e.preventDefault();
var dataString = form.serialize();
var formAction = form.attr('action');
var token = $("input[name=_token]").val();
var indication = $("input[name=indication_name]").val();
$.ajaxSetup({
headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
});
$.ajax({
type: "get",
url: formAction,
data: dataString,
cache: false,
success: function(data) {
console.log(data);
console.log("success");
},
error: function(data) {
console.log(data);
console.log("error");
}
},"json");
});
});
</script>
Controller
use Illuminate\Http\Request;
public function insert(Request $request)
{
if($request->ajax()){
return "AJAX";
}
return "HTTP";
}
But i have only a http response ..
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community