Nimesh
Nimesh

Reputation: 100

form submit in codeigniter using ajax

Here when I submit my form and will check validation in js file and then that will call the kickerLogin() function Got alert message of datastring, then this is not send to my url which is mentioned in ajax but that will submit..........

function kickerLogin(){
    alert('hello friends');
    dataString=$('form[name=kickerLog]').serialize();
    alert(dataString);
    $.ajax({
        type:"POST",
        url:"<?php echo $GLOBALS['base_url']; ?>ajax/user-ajax.php?mode=kickerLogin",
        cache: false,
        data: dataString,
        dataType: "json",

        success: function(data) {
            alert(data);
                if(data.success == "yes")
                {   
                    $('#kickerLog').submit();   
                }
                else if(data.success == "no")
                { 
                    if(data.status=="emailfail"){
                    $('li.log_error').show();
                     $('li.log_error').html("Email id not verified");
                    } 
                    else if(data.status=="rejected"){
                        alert("Your account is inactive by admin");
                    } 

                 else{  
                     $('li.log_error').show();
                     $('li.log_error').html("Invalid Email / Password");
                     $("#loginEmail").css("border","1px solid red");        
                     $("#loginPassword").css("border","1px solid red");    
                 }
                }

                else {
                    alert(" Occured internal Error.please check network connection" );
                }
        }
    });
}

Upvotes: 0

Views: 1331

Answers (3)

Jeyasithar
Jeyasithar

Reputation: 535

It is not recommended to call external files in CI.

//Instead of this
 url:"<?php echo $GLOBALS['base_url']; ?>ajax/user-ajax.php?mode=kickerLogin",

//Use this
//Where ajax is a controller ajax.php user_ajax is a function in it.
 url:"<?php echo site_url();?>/ajax/user_ajax?mode=kickerLogin",

//ajax.php controller
function user_ajax(){
$data['mode'] = $this->input->get('mode');
//Here load the file
$this->load->view('user-ajax');
}

Upvotes: 0

Ajith S
Ajith S

Reputation: 2917

If your js function kickerLogin() is in a js file you can't use '',

Pass your url as one parameter while calling kickerLogin() function

Upvotes: 0

Nil&#39;z
Nil&#39;z

Reputation: 7475

You can't use <?php echo $GLOBALS['base_url']; ?> in your js file. Include this in your view may work then. Instead of <?php echo $GLOBALS['base_url']; ?> use <?=base_url()?> in your view.

Upvotes: 2

Related Questions