检查id是否可用,如果可用,则在代码点火器中使用ajax提交[关闭]

问题描述 投票:-2回答:2

我有一个问题,我想检查用户是否已注册,如果已注册,表单需要提交并显示用户数据,如果没有,则显示用户未在同一页面上注册。我是ajax的新手

<form class="form-group" action="<?php echo site_url('home/verify_usr'); ?>" method="post">
    <table style="width: 100%;">
        <tr><td style="">
            <input class="form-control" type="text" name="reg_id" placeholder="Enter the User ID here.." aria-label="Search" style="width: 100%">
    </td><td>
                    <button type="Submit" class="btn btn-danger">Submit</button>
                </td></tr>
                <tr><td style="text-align: center;color: red">
             <span id="fails">
             <!-- the verification fails comes here -->
            </span></td></tr>
             </table>

             </form>
php jquery ajax forms codeigniter
2个回答
0
投票

HTML:

<form id='yourFormId'>
//add your html
</form>

JS:

<script type="text/javascript">
    $(document).ready(function () {
        $( "#yourFormId" ).submit(function( event ) {
            //event.preventDefault();
            $.ajax({
                beforeSend: function () {
                },
                complete: function () {
                },
                type: "POST",
                url: "<?php echo site_url('controller/checkUserReg'); ?>",
                data: $(this).serialize(),
                success: function (data) {

                }
            });
        });
    });
</script>

PHP:

function checkUserReg(){
// your code to Model->checkUserReg which check user registered or not
// if not reg then reg it else show your user list
}

0
投票

尝试使表单隐藏然后登录后出现然后从会话中获取id

© www.soinside.com 2019 - 2024. All rights reserved.