Home >Backend Development >PHP Tutorial >javascript - laravel, ajax uses the post method to transmit, and an error 500 is reported when obtaining the login user id in the background. It is normal to use the get method.

javascript - laravel, ajax uses the post method to transmit, and an error 500 is reported when obtaining the login user id in the background. It is normal to use the get method.

WBOY
WBOYOriginal
2016-10-23 00:12:511524browse

laravel framework, the frontend uses ajax to submit form data,
when type: 'get', the backend can get the user id through $request->user()->id,
but
when type: 'post ', the background reports error 500 through $request->user()->id.

routes.php

<code>Route::group(['middleware' => 'web'], function () {
    Route::auth();
    //这个url使用post报错
    Route::get('/index/folder', "IndexController@folder");
});</code>

controller

<code>    public function folder(Request $request, FoldersRepository $FoldersRep) {
        return response($request->user()->id);
    }</code>

js

<code>    $.ajax({
        type: 'get',
        url: "/index/folder",
        data: formData,
        success: function (data) {
            console.log(data);
            debugger</code>

What is going on and how to solve it?

Reply content:

laravel framework, the frontend uses ajax to submit form data,
when type: 'get', the backend can get the user id through $request->user()->id,
but
when type: 'post ', the background reports error 500 through $request->user()->id.

routes.php

<code>Route::group(['middleware' => 'web'], function () {
    Route::auth();
    //这个url使用post报错
    Route::get('/index/folder', "IndexController@folder");
});</code>

controller

<code>    public function folder(Request $request, FoldersRepository $FoldersRep) {
        return response($request->user()->id);
    }</code>

js

<code>    $.ajax({
        type: 'get',
        url: "/index/folder",
        data: formData,
        success: function (data) {
            console.log(data);
            debugger</code>

What is going on and how to solve it?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn