Codigniter架構PHP POST提交到兩個地址實現

來源:互聯網
上載者:User

Codigniter架構使用jquery+ajax/" target="_blank">jquery ajax代碼如下:

 代碼如下 複製代碼

 <form action="<?php echo @htmlspecialchars($url['login_url']) ?>"  method="post" enctype="application/x-www-form-urlencoded" name="form1" id="form1">
        <p><label>工資號:</label>
            <input name="Login.Token1" class="text" type="text" id="token1" />
        </p>
        <p><label>密 碼:</label>
            <input name="Login.Token2" class="text" type="password" id="token2" />
        </p>
        <p>
            <input name="登入" type="submit" id="user_login" value="登入" />
            <input type="reset" value="重設" />
        </p>
        <b style="color:red"><?php echo $this->session->flashdata('error'); ?></b>
    </form>
<script>
    $(function(){
        $("#user_login").click(function(){
            var username = $("#token1").val();
            var salary_no = $("#token2").val();
            $.ajax({
                type: "POST",
                data: "username="+username+"&salary_no="+salary_no,
                url: "<?php echo site_url('home/ajax_check_username')?>",
                dataType: "text",
                cache: false,
                error: function(){alert('error');},
                success: function(data){
                    if(data == 'yes'){
                        location.href="<?php echo site_url('home/index')?>";
                    }else{
                        form1.submit();
                    }
                }
            });
            return false;
        });
    });
</script>

ajax提交到home控制器代碼:

 代碼如下 複製代碼


    #提交到本地
    function ajax_check_username(){
        //redirect('home/index');
        $username = $this->input->post("username");
        $salary_no = $this->input->post("salary_no");
        if($this->user_mdl->check_ajax_user($username,$salary_no)){
            $this->session->set_userdata('salary_no', $salary_no);
            $this->session->set_userdata('username', $username);
            echo "yes";
        }else{
            echo "no";
        }
    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.