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
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题