Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript不使用codeigniter?_Javascript_Php_Jquery_Codeigniter - Fatal编程技术网

javascript不使用codeigniter?

javascript不使用codeigniter?,javascript,php,jquery,codeigniter,Javascript,Php,Jquery,Codeigniter,我只是想学习一些从codeigniter开始的php framework.ans。所以你们可以理解,我对codeigniter是全新的。我只是想在用户名和密码字段为空时显示一条错误消息。如果不是,请提交表单。我需要用户和服务器端验证。问题是js没有显示错误消息,也不提交。 这里是我的视图代码-> <body> <center> <h2>LOGIN</h2> <form method="post" nam

我只是想学习一些从codeigniter开始的php framework.ans。所以你们可以理解,我对codeigniter是全新的。我只是想在用户名和密码字段为空时显示一条错误消息。如果不是,请提交表单。我需要用户和服务器端验证。问题是js没有显示错误消息,也不提交。 这里是我的视图代码->

<body>
    <center>
        <h2>LOGIN</h2>
        <form method="post" name="loginForm">
            <table cellpadding="4" cellspacing="4">
                <tr>
                    <td>USERNAME</td>
                    <td><input type="text" name="username" id="iusername" /></td>
                </tr>
                <tr>
                    <td>PASSWORD</td>
                    <td><input type="password" name="password" id="ipassword" /></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td><input onclick="checkInputFields()" type="button" value="Login" name="submit" /></td>
                </tr>
            </table>
        </form>
        <br />

        <!-- Label to display error message -->
        <?php
        if(!empty($errorMessage)){?>
            <label name="errorMessage" id="ierrorMessage"><?php echo $errorMessage;?></label>
        <?php
        }
        ?>

    </center>
</body>
控制器功能工作完全正常。我检查了,但js不工作,为什么?我还想检查如何在代码中检查服务器端和客户端的验证,如果js关闭[如果我的意愿有效]from将不提交。php验证将不起作用。我还想知道我的编码架构有什么问题。experience Brothers->请帮助我。

标签

<label name="errorMessage" id="ierrorMessage"><?php echo $errorMessage;?></label>

使用jquery。像这样尝试

$(“#登录”)。在('click',function()上{
用户名=$(“#iusername”).val();
密码=$(“#ipassword”).val();
如果(用户名=“”| |密码=“”){
log(“您不能将用户名和密码字段留空。”);
警告(“您不能将用户名和密码字段留空。”);
}
否则{
$(“#loginForm”).submit();
}
});

登录
用户名
密码


哦!我可能无法理解。但为什么表单未提交。请尝试更改输入按钮的属性“名称”。document.loginForm.submit()无法使用此输入名称。您可以使用codeigniter验证轻松检查此空白输入,为什么不使用它????
    public function index(){
    if($this->input->post('submit')){
        $uName=$this->input->post('username');
        $uPass=$this->input->post('password');

        if($uName == "" || $uPass == ""){
            $message['errorMessage']='You cant left username and password field empty.';
            $this->load->view('login',$message);
        }else{
            if($this->varifyuser->checkuser($uName,$uPass)){

            $this->session->set_userdata('loggedin', true);

            redirect(base_url()."home", 'refresh');

            }else{
                $message['errorMessage']='Invalid username or password';
                $this->load->view('login',$message);
            }
        }
    }
    else
    {
        $this->load->view('login');
    }
}
<label name="errorMessage" id="ierrorMessage"><?php echo $errorMessage;?></label>
document.getElementById('ierrorMessage') /*is null*/