简体   繁体   中英

how to pass a javascript variable to laravel route?

Script code:

 <script type="text/javascript">
  function getValue(){
    var getvalue=document.getElementById('brand').value;
    window.location='products' +getvalue;
  }
</script>

This is my script code. Here I am trying to pass the value of the variable 'getvalue'to the route.

Route:

Route::get('products/{getvalue}','categoryController@bValue');

This is my route. Here I am trying to pass the getvalue to the controller.

Controller code:

  public function bValue(Request $getvalue)
{

    echo $getvalue;
}

Try this may it will work..

 // Javascript
    <script type="text/javascript">
      function getValue(){
        var getvalue=document.getElementById('brand').value;
        window.location='products/' +getvalue;
      }
    </script>

// Php
    public function bValue($getvalue)
    {
        echo $getvalue;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM