Welcome Guest, Not a member yet? Register   Sign In
jQuery ajax poll in CI
#1

[eluser]babazumbula[/eluser]
Hi there,

On home page I have login form and ajax poll. So controller is:
Code:
<?php
    
class Login extends Controller{
    
    function  index(){
        $this->load->view('login_form_view');                
    }

function validate_credentials(){
        $this->load->library('form_validation');
        $this->load->model('membership_model');
        $this->form_validation->set_rules('username','Username','callback_correct_credentials');

        if($this->form_validation->run() == false){
           $this->index();
        }
At this point login and ajax poll work fine, but when they submit incorrect credentials
Code:
$this->form_validation->run()
returns false, so
Code:
$this->index()
takes place and error is displayed right under the login form. At this point ajax poll won't work anymore. When "vote" button is clicked nothing happens. Here is jQuery code:
Code:
$(document).ready(function(){
        $("#poll #submit").click(function () {
                    var val = $('input:radio[name=vote]:checked').val();
            $("#poll").html('Retrieving...');
            $.ajax({
                type: "POST",
                data: "data=" + val,
                url: "<?php echo base_url();?>login/poll/",
                success: function(msg){
                    $("#poll").html(msg)
                }
            });
        });
    });
For sake of clarity I'm presenting only essential code, which works when url is: login/index.php , but doesn't if url is: login/validate_credentials. I wonder why is so, since both url load the same view?
#2

[eluser]bretticus[/eluser]
Perhaps you should show the login/poll code.
#3

[eluser]babazumbula[/eluser]
Code in the login/poll I simplified as much as possible so in login/poll I put:
Code:
$var = $this->input->post('data');
echo $var;
and still echoing $var correctly while url:login/index.php, but won't when url:login/validate_credentials




Theme © iAndrew 2016 - Forum software by © MyBB