dougan5772 2017-09-18 13:58
浏览 54
已采纳

如何将变量从控制器解析为javascript并使用变量重定向页面

I created a form with javascript validation. if the validation is complete i will redirect to another page with javascript. but I need invoice variable from a controller that I need to send to the page I point to later.

my javascript:

$.ajax({
    url  : baseURL +"checkout/endVerify_order",
    type : "GET",
    data : {starssecure: csrf, gex: g, almt: addr, prov: na_prop, city: na_cit, w: wei, exp: ex, resex: exresul, pay: mePay, bnk: bnkifyes, grt: gTotat},
    beforeSend: function(){
        $(".bg-form-che").removeClass("hidden");
    },
    success: function (sndOrder){
        $(".bg-form-che").addClass("hidden");
        if(sndOrder == "Lnswg&g2390"){
            $(".bnk_in").html("Choose Bank!");
            $(".alam_in").html("");
            $(".ex_in").html("");
            $(".prop_in").html("");
            $(".city_in").html("");
            $(".resex_in").html("");
            $(".pay_in").html("");
            $(".pushp").html("Lengkapi Form diatas!");
            $(".citKey").removeClass("border-error");
            $("#addrKey").removeClass("border-error");
            $("#propKey").removeClass("border-error");
            $(".tb_result").removeClass("border-error");
        }else if(sndOrder == "validate_complete"){
            $("#inv").val(sndOrder.datap);
            window.location.href = baseURL + 'finishorder';
        }
    }
    });

and my controller :

function endVerify_order(){
echo "validate_complete";
$invoice = "AB18253";
$datap = $invoice;
echo json_encode($datap);
}

and my view for finishorder :

div class="col-lg-12 col-xs-12">
        <div id="shf" class="row">
            <div class="col-lg-12 col-xs-12">
            <div class=" text-center">
                <i class="glyphicon glyphicon-ok bort"></i><br>
                <h4>Your Order is Successfully</h4>
                <b>No. Invoice #<span id="inv"></span></b>
                <p class="text-justify">Thankyou for Order.</p>
            </div>
            </div>
        </div>
        </div>
  • 写回答

1条回答 默认 最新

  • drhzn3911 2017-09-18 14:05
    关注

    In Controller, jsonize the values as following,

    function endVerify_order(){
    $data['status'] =  "validate_complete";
    $data['invoice'] = "AB18253";
    $data['datap'] = $invoice;
    echo json_encode($data);exit;
    }
    

    Now you can directly check if(sndOrder.invoice == "Lnswg&g2390"){ }

        window.location.href = baseURL + 'finishorder/'+sndOrder.invoice;
    

    You can access in controller function,

    function finishorder($invoiceid)
    { 
        //$invoiceid which is sent from javascript
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源