Json giving 301 Moved Permanently

六月ゝ 毕业季﹏ 提交于 2019-12-10 15:16:21

问题


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."

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

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

My 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?


回答1:


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

url: '/admin/submit-scan'

Update

As mentioned in Laravel4 POST unexplained redirect to GET

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

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



来源:https://stackoverflow.com/questions/18934588/json-giving-301-moved-permanently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!