[英]PHP & Javascript Toastr
Is there a way to show or display JS toastr alerts trought PHP code.有没有办法通过 PHP 代码显示或显示 JS toastr 警报。 This is the code and the alert message.这是代码和警报消息。
echo "<script type='text/javascript'>_toastr('Your email is not registered, please check.');</script>";
Should be no problem because PHP is server-side and you can prepare your toastr eg with a session and then put the PHP result in the script-tag.应该没问题,因为 PHP 是服务器端的,你可以准备你的 toastr,例如使用会话,然后将 PHP 结果放在脚本标签中。 Just generate a PHP-Session-Array where the error is thrown:只需生成一个抛出错误的 PHP-Session-Array:
<?php
session_start()
$_SESSION['toastr'] = array(
'type' => 'error', // or 'success' or 'info' or 'warning'
'message' => 'error message here!',
'title' => 'title here!'
);
?>
Now you can fill the script-Tag on the page where the toastr should display:现在您可以在 toastr 应显示的页面上填写 script-Tag:
<script>
$(function(){
<?php
// toastr output & session reset
session_start();
if(isset($_SESSION['toastr']))
{
echo 'toastr.'.$_SESSION['toastr']['type'].'("'.$_SESSION['toastr']['message'].'", "'.$_SESSION['toastr']['title'].'")';
unset($_SESSION['toastr']);
}
?>
});
</script>
Always make sure to load jquery before!一定要确保之前加载jquery!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.