简体   繁体   中英

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" );
                }
        }
    });
}

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

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

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

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');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM