[英]PHP echo JS which includes PHP variable
我有sendForm.php文件,這是使用PHPMailer發送表單的php。 在標簽之間有回聲,我需要在標簽之間使用PHP變量。 這有可能嗎? 我知道這太結合了PHP和JS,但是我能做什么......我需要一個窗口彈出窗口,這也是我使用JS的原因。 echo本身只打印到網頁本身。
$totalSize = ($totalSize/(1024*1024));
$totalSize = round($totalSize,2);
if(!$mail->Send()) {
echo "Error sending form! You are trying to send too large files. Their size is: ", $totalSize, " MB";
echo '<script type="text/javascript">alert("Error sending form! You are trying to send too large files. Their size is: ??? ");</script>';
}
如何在JS內部打印$ totalSize變量代替第二個回聲中的那些問號呢? 謝謝你的幫助。 我還是個初學者。
if(!$mail->Send()) {
echo "Error sending form! You are trying to send too large files. Their size is: ". $totalSize. " MB";
echo '<script type="text/javascript">alert("Error sending form! You are trying to send too large files. Their size is: '. $totalSize. '");</script>';
}
//我糾正了第一個echo中的一些錯誤(用點替換逗號)
PHP是服務器端語言 ,而JavaScript是客戶端語言 。 如果您嘗試在服務器端驗證表單而不重新加載頁面(並讓JavaScript彈出警告),請查看AJAX 。
嘗試這個
if(!$mail->Send()) {
echo "Error sending form! You are trying to send too large files. Their size is: ".$totalSize." MB";
?>
<script type="text/javascript">
alert("Error sending form! You are trying to send too large files. Their size is: <?php echo $totalSize;?> ");
</script>
<?php }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.