2015-06-22 65 views
-1

我想提醒消息,但它不能与我的字符串一起工作。在JS警报中显示PHP变量

echo "<script>alert('$lang['ALERT']'); 
window.location.href ='index.php'; 
</script>"; 

不工作...帮助

+0

你想要提醒什么? –

+0

储存在$ lang中的字符串['ALERT'] – ushtown

+0

请确保'$ lang ['ALERT']'是您所期望的。如果有什么**,它会发出警报吗? – ToothlessRebel

回答

0

你混的报价。保持简单,

echo "<script>alert('".$lang['ALERT']."'); 
     window.location.href ='index.php'; 
     </script>"; 
+1

它的工作....赞赏Rikesh – ushtown

0

试试吧。

<script> 
var alertMsg = "<?php echo $lang['ALERT'] ?>"; 
alert(alertMsg); 
window.location.href ='index.php'; 
</script>; 
+0

它没有工作,感谢它作为rikesh – ushtown

0

你没有正确引用您的变量

<?php 
$lang['ALERT'] = 'mystring'; 
echo "<script>alert('".$lang['ALERT']."');window.location.href ='index.php';</script>"; 
?> 

Here's the eval

0

试试这个

<script> 
    alert(<?=$lang['ALERT']; ?>); 
    window.location.href ='index.php'; 
</script> 
0

报价是问题

<?php $alert=$lang['ALERT'];?> 

    <script> 
    alert('<?php echo $alert?>'); 
    window.location.href ='index.php'; 
    </script>;