jquery's ajax method, for GET requests, will splice the url and query parameters into http://xxx.xxx/aaa/bbb?arg1=ddd
to initiate the request.
I define a route like Route::get('aaa/bbb/{arg1}'). The request that this route can recognize is http://xxx.xxx/aaa/bbb/ddd.
For such a problem, how should laravel's routing be written to correctly respond to the front-end AJAX request?
Post the solved code memo:
Route:Route::get('getProjectInfoByAPI/{url?}', 'ProjectController@getProjectInfo');
front end:
$.ajax({
url: 'getProjectInfoByAPI',
type: 'GET',
data: {
url: xxx,
},
dataType: 'json',
success: function(response){
}
});
});
伊谢尔伦2017-05-16 16:49:02
Route::get('/aaa/bbb/{arg1?}','UserController@arg1');
$.ajax({
type: 'get',
url: '/aaa/bbb',
data: {'arg1': 'ddd'},
headers: {'X-CSRF-Token': $('meta[name=csrf-token]').attr('content')},
dataType: 'json',
success: function (msg) {
}
});