簡體   English   中英

如何在沒有URL顯示參數的情況下使用get發送數據?

[英]How to send data using get without display parameters in url?

我的情況是這樣的:

我的視圖刀片laravel像這樣:

{!! Form::open(['route' => 'shop.payment']) !!}
    <input type="hidden" name="result_type">
    <input type="hidden" name="result_data"">
    ...
    <input type="radio" name="payment_method" value="transfer">
    ....
    <checkout-view></checkout-view>
{!! Form::close() !!}

在視圖中,刀片laravel存在checkout視圖的vue組件

像這樣的組件:

<script>
    export default{
        template:'<button @click="checkout" class="btn btn-danger pull-right" type="submit">Checkout</button>',
        methods: {
            checkout(e){
                if(window.Laravel.hasOwnProperty('auth')) {
                    $('#payment-form').attr('action', '/shop/payment/checkout')
                    return true;
                }
                else {
                    $('#payment-form').attr('action', '/shop/detail')
                    $("#payment-form").attr('method', 'get')
                    return true
                }
            }
        },
    }
</script>

我的路線laravel像這樣:

Route::group(['prefix' => 'shop','as'=>'shop.'], function () {
    Route::get('detail', function(){
        return view('shop.detail');
    });
});

如果沒有身份驗證,它將運行else URL,如下所示:

http://myshop.dev/shop/detail?_token=FLFJ7MfWi1DZv88Uzk2lrBgVXLN6Y3WHTpskDIED&result_type=&result_data=&payment_method=轉移

我想刪除參數,所以這樣的網址:

http://myshop.dev/shop/detail

我嘗試更改為post

我變成這樣:

$('#payment-form').attr('action', '/shop/detail')
$("#payment-form").attr('method', 'post')
return true

Route::post('detail', function(){
    return view('shop.detail');
});

但這不起作用,存在錯誤:

POST http://myshop.dev/shop/detail 405(不允許使用方法)

什么是解決我的問題的正確解決方案?

您可以使用Inputget方法這樣做:

視圖

{!! Form::open(['route' => 'shop.payment','method' => 'GET']) !!}
    <input type="hidden" name="result_type">
    <input type="hidden" name="result_data"">
    ...
    <input type="radio" name="payment_method" value="transfer">
    ....
    <checkout-view></checkout-view>
{!! Form::close() !!}

路線

Route::get('/test/route', 'TestController@yourFunction');

控制者

public function yourFunction(){

    $result_type = Input::get('result_type');
    $result_data = Input::get('result_date');
    ......

}

我希望你明白。

Route::group(['prefix' => 'shop','as'=>'shop.'], function () {
    Route::get('detail', function(){
    return view('shop.detail');
    });
});

我相信這條路線的顯示方式是shopdetail ,而不是shop / detail

鍵入命令php artisan route:list以查看laravel如何看到網址。

如果沒有身份驗證,請使用返回重定向到其他路由,而不是返回視圖。 在另一條您要重定向的路由中,返回要在沒有經過身份驗證的用戶時顯示的原始視圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM