在CI中进行表单验证后,Sweet Alert2没有出现

时间:2019-11-13 02:52:04

标签: codeigniter sweetalert2

您好,我尝试在验证成功后显示警报,但警报未显示。 代码错误或什么??

public function dashboard()
	{
		$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]');
		$this->form_validation->set_rules('pass', 'Password', 'trim|required|min_length[5]');
		if($this->form_validation->run() != false){
			echo "<script>
			Swal.fire('Login Success')
			</script>";
		}else{
			$this->load->view('login');
		}
	}

1 个答案:

答案 0 :(得分:0)

是否记录了任何错误?我通常用php关闭,然后执行Javascript,然后再次打开它。

public function dashboard()
    {
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]');
        $this->form_validation->set_rules('pass', 'Password', 'trim|required|min_length[5]');
        if($this->form_validation->run() != false){
            ?>
            <script>
                 Swal.fire('Login Success');
            </script>
            <?php
        }else{
            $this->load->view('login');
        }
    }