简体   繁体   English

Jquery Alert PHP变量

[英]Jquery Alert PHP variable

Is there away to alert this variable without using ajax? 有没有使用ajax警告这个变量? need guide, trying todo this in one page heres my code. 需要指导,尝试在一页中看到我的代码。

<?php
if($totalActive == 10 OR $totalActive < 10){
echo "<input id='activo' type='hidden' value='$totalActive'>";
?>
    <script type="text/javascript">
    var tom = $("#activo").val();
    alert("Your Credit Balance will expires in  "+ tom +"days \n Please buy more credits to extend the expire date");
    window.location.href = "Outbox.php";
    </script>
<?php
}//continue php scripts

im trying to alert how many days left, does the user have before its credit balance expires, i think you cant combine php with jquery, but is there away to do this? 我试图提醒还剩下多少天,用户在信用余额到期之前有没有,我认为你不能将php与jquery结合起来,但是有没有做到这一点?

You can call PHP in javascript, but not javascript in PHP. 你可以用javascript调用PHP,但不能用PHP调用javascript。

Also you don't need to do an OR , you can just check if $totalactive is less than or equal to 10 using <= . 此外,您不需要执行OR ,您只需使用<=检查$totalactive是否小于或等于10

<?php
  if($totalActive <= 10){
?>
    <script type="text/javascript">
    alert("Your Credit Balance will expires in <?php echo $totalActive; ?> days \n Please buy more credits to extend the expire date");
    window.location.href = "Outbox.php";
    </script>
<?php
}

Another way, which could look more flexible if you want to use that variable in functions or just keep your javascript code in your .js files, would be to get the value in a hidden element such as: 另一种方法,如果你想在函数中使用该变量或者只是在你的.js文件中保存你的javascript代码,它可能看起来更灵活,就是在隐藏元素中获取值,例如:

<input id="expireDays" type="hidden" value="<?php echo $totalActive; ?>" />

Then you would only need to retrieve it with jQuery or javascript on document ready: 然后你只需要在文档准备好的jQuery或javascript上检索它:

$(document).ready(function() {
   var expiredDays = $('#expireDays').val();

   alert("Your Credit Balance will expires in  "+ expiredDays +"days \n Please buy more credits to extend the expire date");

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM