The website realizes the separation of front-end and back-end, and only calls back-end services through the API.
The back-end service is written in PHP framework Laravel5.2.
Route::group(['middleware' => ['web']], function () {
//
Route::get('/', function () {
/* 返回前端应用资源 */
return "Hello";
});
});
Route::group(['middleware' => ['api']], function () {
/* 不用认证就可以访问的路由 */
Route::post('/auth/login', 'Auth\AuthController@login');
Route::post('/auth/register', 'Auth\AuthController@register');
/* 需要认证才可以访问的路由 */
Route::group(['middleware' => ['auth']], function () {
Route::get('/c', function () {
return "课程链表";
});
});
});
The above code calls
{
"email": "admin@a.com",
"pasword": "adsf"
}
Why can't json data be returned?
There are also middlewaresapi
What is the difference between web
?
迷茫2017-05-16 16:56:12
See: https://laravel.com/docs/5.2/responses#json-responses
Oh, sorry, submitted a request and should have added this
$.ajax({
type: 'POST',
contentType: "application/json",
dataType: 'json',
...
});