My problem is not work AJAX Laravel For me in ver5.2 how to solve this problem my error:
Route [category] not defined. (View: C:\wamp\www\pc\resources\views\admin\category.blade.php)
my Route file:
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('category', 'categoryController@index');
});
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::post('category', 'categoryController@create');
});
my controller:
public function create(messageRequest $request)
{
try {
Category::create($request->all());
return response()->json(array('sms'=>'save Success'));
}catch (Exception $e){
return response()->json(array('err'=>'error'));
}
}
my javascript:
<script>
$('#submit').on('click', function (e) {
e.preventDefault();
var data = $('#create').serialize();
$.ajax({
type: 'post',
url: '{!! URL::route('category') !!}',
data: data,
success: function (data) {
alert(data.sms);
console.log('data');
},
error:function(){
alert(data.err);
console.log('data');
}
});
});
</script>