[英]I am trying to pass some PHP variables and Javascript variable into url in Javascript window.location.href
我正在尝试将一些 PHP 变量和 Javascript 变量名称“引用”传递到 Javascript 中的 URL 中。 以下是运行良好的 PHP 变量
//Collect user's data
$amt = $_GET['amount'];
$email = $_GET['email'];
$firstname = "bas";
$lastname = "aik";
<script>
callback: function(response){
const referenced = response.reference;
window.location.href='successful.php?successfullypaid=referenced&email=<?php echo $email; ?>';
},
<script?
我在下面粘贴了我的整个代码供您查看。
<?php
//sanitize form inputs
$sanitizer = filter_var_array($_POST, FILTER_SANITIZE_STRING);
//Collect user's data
$amt = $_GET['amount'];
$email = $_GET['email'];
$firstname = "bas";
$lastname = "aik";
//Make sure fields are not empty
//if(empty($amt)) {
// header("Location: deposit.php");
//}else{
?>
<div class="modal-body">
<p>Confirm Online payment to pay with paystack</p>
<form >
<script src="https://js.paystack.co/v1/inline.js"></script>
<button type="button" class="btn btn-success confirm-button" onclick="payWithPaystack()"> Confirm </button>
<a class="btn btn-danger" href="index.php"> Decline </a>
</form>
</div>
<!-- <div class="modal-footer">
<a href="index.php"> <button type="button" class="btn btn-primary">Go to Account</button></a>
</div>-->
</div>
</div>
</div>
</div>
<script>
function payWithPaystack(){
const api = "pk_test_71bd9a7489bee5e300594cabeac43344eed2ef5c";
var handler = PaystackPop.setup({
key: api,
email: '<?php echo $email; ?>',
amount: <?php echo $amt*100; ?>,
currency: "NGN",
ref: ''+Math.floor((Math.random() * 1000000000) + 1), // generates a pseudo-unique reference. Please replace with a reference you generated. Or remove the line entirely so our API will generate one for you
/*firstname: <?php echo $firstname; ?>,
lastname: <?php echo $lastname; ?>,*/
metadata: {
custom_fields: [
{
/*display_name: <?php echo $firstname; ?>,
variable_name: <?php echo $lastname; ?>,
value: "+2348012345678"*/
}
]
},
callback: function(response){
const referenced = response.reference;
window.location.href='successful.php?successfullypaid=referenced&email=<?php echo $email; ?>';
},
onClose: function(){
alert('window closed');
}
});
handler.openIframe();
}
</script>
我已经尝试了这个问题的所有答案如何在 php 中的 location.href 中传递多个参数? ,但他们不为我工作。
window.location.href='successful.php?successfullypaid=referenced&email=<?php echo $email; ?>';
这是唯一接近我想要的解决方案,PHP 变量工作正常,但 javascript 变量不起作用
试试这个,现在你只是制作一个字符串,与 PHP 不同,javascript 不允许你在字符串中传递变量。
window.location.href=`successful.php?successfullypaid=${referenced}&email=<?=$email; ?>`;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.