laravel Json 给出 301 Moved Permanently

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18934588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:27:39  来源:igfitidea点击:

Json giving 301 Moved Permanently

javascriptphpjsonlaravellaravel-4

提问by CodeGuru

on Firefox, only on firefox it will popup and give you a warning "This web page is being redirected to a new location. Would you like to resend the for form you have typed to the new location."

在 Firefox 上,只有在 Firefox 上它才会弹出并给你一个警告“这个网页正在被重定向到一个新的位置。你想把你输入的表单重新发送到新的位置吗?”

I got no form , i use javascript to extract values from textbox

我没有表格,我使用 javascript 从文本框中提取值

I checked on firebug it says PUT /admin/submit-scan/ 301 moved permanently PUT submit-scan 302 Found

我检查了萤火虫,它说 PUT /admin/submit-scan/ 301 永久移动 PUT submit-scan 302 Found

My JS

我的JS

function submitGoods(){
    var registeredNo = $('input[name=registeredno]').val();
    var weight = $('input[name=weight]').val();
        $.ajax({
            type: 'PUT',
            url: '/admin/submit-scan/',
            data: {
                registeredNo: registeredNo,
                weight: weight,
                _token: csrfToken
            },
            dataType: 'json'
        }).done(function(data){

                data = $.parseJSON(data);
            });

}

My Route

我的路线

Route::put('submit-scan', 'Controllers\Admin\DashboardController@putUpdateSubmitScan');

My controller

我的控制器

 public function putUpdateSubmitScan()
    {
        if (Request::ajax())
        {
            return Response::json(array('success' => 1, 'data' => "test"));
        }
    }

Any idea what went wrong?

知道出了什么问题吗?

回答by JofryHS

Removing the trailing slash should do the trick (most probably prior to Laravel 4.1, see below).

删除尾部斜杠应该可以解决问题(很可能在 Laravel 4.1 之前,见下文)。

url: '/admin/submit-scan'

Update

更新

As mentioned in Laravel4 POST unexplained redirect to GET

Laravel4 POST unexplained redirect to GET 所述

Laravel bootstrap/start.phpis calling $app->redirectIfTrailingSlash();which seems to be the culprit. This has been changed in Laravel 4.1:

Laravelbootstrap/start.php正在调用$app->redirectIfTrailingSlash();这似乎是罪魁祸首。这在 Laravel 4.1 中已经改变:

http://laravel.com/docs/upgrade#upgrade-4.1

http://laravel.com/docs/upgrade#upgrade-4.1