简体   繁体   English

如何使用JavaScript来警告这些PHP错误消息?

[英]How can I use javascript to alert these PHP error messages?

How can I javascript alert my php error messages? 我该如何用JavaScript提醒我的PHP错误消息? Here is my code: 这是我的代码:

<?php echo showmessage($msg)?>

I want to make it into an alert, how can I do that? 我想使其成为警报,该怎么办?

 ?>
  <script type="text/javascript">
    alert("The error is  <?php echo $msg ?>");
    history.back();
  </script>
<?php

Or 要么

echo '<script language="javascript">';
echo 'alert(Message here)';
echo '</script>';

The use of json_encode makes sure that characters that needs to be escaped are escaped. 使用json_encode可确保对需要转义的字符进行转义。

<script>
  alert(<?php echo json_encode($msg); ?>);
</script>

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

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