简体   繁体   English

javascript变量未以以下形式显示codeigniter的验证错误

[英]javascript variable doesn't show validation errors of codeigniter in the form

i'm using ci built-in validation_errors() function in my login form. 我在登录表单中使用ci内置的validate_errors()函数。 everything works fine and i can see true validation errors in my view. 一切正常,我可以在视图中看到真正的验证错误。 but when i echo validation errors into my js variable in the script to show it in the customized notifications, nothing shows. 但是,当我在脚本中将验证错误回显到我的js变量中以在自定义通知中显示该错误时,什么也没有显示。 here is my code: 这是我的代码:

    <?php if (isset($validation_error)){
        echo $validation_error;} ?>
    <script>
        var text=  "<?php echo $validation_error;?>";
    </script>
    <script src="<?php echo base_url();?>resources/js/assets/errore-not.js" type="text/javascript">
    </script>

when i pass any php variables or strings in "text" variable of script, it shows the notification correctly. 当我在脚本的“文本”变量中传递任何php变量或字符串时,它会正确显示通知。 this is my notify code: 这是我的通知代码:

$(document).ready(function notification () {
    $.notify({
        icon: "notifications",
        message: text

    }, {
        type: 'danger',
        timer: 4000,
        placement: {
            from: 'top',
            align: 'center'
        }
    });
});

How can I do this? 我怎样才能做到这一点?

You can pass the php variable value inside javascript variable like this. 您可以像这样在javascript变量内传递php变量值。

<?php if (isset($validation_error)){
    echo $validation_error; ?>
<script>
    var text= '<?php echo $validation_error;?>';
</script>
<?php } ?>

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

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