Home > Backend Development > PHP Tutorial > Laravel Ajax POST数据问题

Laravel Ajax POST数据问题

WBOY
Release: 2016-06-06 20:08:50
Original
1284 people have browsed it

js代码:

<code>$('#resume_form .button-submit').click(function () {
                var data = $("#resume_form").serializeArray();
                $.ajax({
                    type: 'POST',
                    url: '/delivery',
                    dataType: 'json',
                    cache: false,
                    data,
                    headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function(data){
                    console.log(data.status);
                    },
                    error: function(xhr, type){
                    alert('Ajax error!')
                    }
                });
            }).hide();</code>
Copy after login
Copy after login

服务端响应代码:

<code>public function store(Request $request)
    {
        return response()->json(array(
            'status' => 1,
            'msg' => 'ok',
        ));
    }</code>
Copy after login
Copy after login

Laravel Ajax POST数据没有经过Auth中间件,但是会报302错误,并且会Views里可以看到会加载login视图Laravel Ajax POST数据问题

对应路由文件如下:
Laravel Ajax POST数据问题

路由信息
Laravel Ajax POST数据问题

Web中的中间件
Laravel Ajax POST数据问题

回复内容:

js代码:

<code>$('#resume_form .button-submit').click(function () {
                var data = $("#resume_form").serializeArray();
                $.ajax({
                    type: 'POST',
                    url: '/delivery',
                    dataType: 'json',
                    cache: false,
                    data,
                    headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function(data){
                    console.log(data.status);
                    },
                    error: function(xhr, type){
                    alert('Ajax error!')
                    }
                });
            }).hide();</code>
Copy after login
Copy after login

服务端响应代码:

<code>public function store(Request $request)
    {
        return response()->json(array(
            'status' => 1,
            'msg' => 'ok',
        ));
    }</code>
Copy after login
Copy after login

Laravel Ajax POST数据没有经过Auth中间件,但是会报302错误,并且会Views里可以看到会加载login视图Laravel Ajax POST数据问题

对应路由文件如下:
Laravel Ajax POST数据问题

路由信息
Laravel Ajax POST数据问题

Web中的中间件
Laravel Ajax POST数据问题

还没弄清楚。
不过,你AJAX传递数据的data,应该写成data: data

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