第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 laravel 在 jquery 中使用 window.location.href

使用 laravel 在 jquery 中使用 window.location.href

PHP
元芳怎么了 2021-11-26 17:44:11
代碼:<script>    $(document).ready(function(){        $("#start-date-1").datepicker();        $("#end-date-1").datepicker();        $("#book_now").click(function(e){            e.preventDefault();            locations = $("#location").val();            start_date = $("#start-date-1").val();            end_date = $("#end-date-1").val();            guests = $("#guests").val();            if(locations=='' && start_date!='' && end_date!='' && guests!='')            {                $("#location").addClass("red_border");            }            else if(locations!='' && start_date!='' && end_date!='' && guests!='')            {                window.location.href="{{URL::to('s?location="+locations+"')}}";            }        });    });</script>在這段代碼中,我只是獲取值,locations, start_date, end_date, guests并且所有變量值都顯示在警報(bào)中,但是當(dāng)我單擊book_now它時(shí)會(huì)重定向我,window.location.href但locations查詢字符串中的值未正確顯示。它是http://localhost/luxvacationrentalhomes.com/s?location=&quot;+locations+&quot;而且應(yīng)該是http://localhost/luxvacationrentalhomes.com/s?location=2。我怎樣才能解決這個(gè)問題?
查看完整描述

2 回答

?
夢(mèng)里花落0921

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超6個(gè)贊

window.location.href="{{URL::to('s?location="+locations+"')}}";

您在這里混合了前端/后端參考框架。里面的一切{{}}都由后端的模板引擎處理。您"在 javascript 中打開一個(gè),然后在模板引擎中關(guān)閉它,這不起作用。

我使用 javascript 字符串替換來解決類似的問題,即在后端使用路由生成包含占位符的 url,然后使用 javascript 將實(shí)際值替換為前端的 url。

window.location.href="{{URL::to('s?location=ReplaceMeWithLocation')}}"
    .replace('ReplaceMeWithLocation', location);

或者,您可以使用字符串模板而不是占位符,但原理是相同的。

window.location.href=`{{URL::to('s?location=${location}')}}`


查看完整回答
反對(duì) 回復(fù) 2021-11-26
?
慕森卡

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超8個(gè)贊

<script>

    $(document).ready(function(){

        $("#start-date-1").datepicker();

        $("#end-date-1").datepicker();

        $("#book_now").click(function(e){

            e.preventDefault();

            locations = $("#location").val();

            start_date = $("#start-date-1").val();

            end_date = $("#end-date-1").val();

            guests = $("#guests").val();

            if(locations=='' && start_date!='' && end_date!='' && guests!='')

            {

                $("#location").addClass("red_border");

            }

            else if(locations!='' && start_date!='' && end_date!='' && guests!='')

            {

                window.location.href="{{URL::to('s')}}" + "?location=" + locations;

            }

        });

    });

</script>


查看完整回答
反對(duì) 回復(fù) 2021-11-26
  • 2 回答
  • 0 關(guān)注
  • 374 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)