简体   繁体   中英

Laravel pass javascript variable to route

I need to pass searchWord to code value in laravel route

    searchWord = $('.searchBox').val();
    var jobs = $('input[name=jobs]:checked').val();
    console.log("num value");
    window.location.href = '{{route("post.search.index",["code"=>9987])}}';

i tried

    searchWord = $('.searchBox').val();
    var jobs = $('input[name=jobs]:checked').val();
    console.log("num value");
    window.location.href = '{{route("post.search.index",["code"=>'searchWord '])}}';

but it reads it as text

instead of window.location.href = '{{route("post.search.index",["code"=>'searchWord '])}}';

use

window.location.href = '{{route("post.search.index",["code"=>'+searchWord+ '])}}'; or window.location.href = "{{route(\\"post.search.index\\",[\\"code\\"=>"+searchWord+ "])}}";

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