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
Release: 2016-10-23 00:12:51
Original
1531 people have browsed it

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>
Copy after login
Copy after login

controller

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

js

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

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>
Copy after login
Copy after login

controller

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

js

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

What is going on and how to solve it?

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template