2013-09-30 118 views
0

在這裏,當我提交我的表單,並將檢查js文件中的驗證,然後將調用kickerLogin()函數 得到了datastring的警報消息,那麼這不會發送到我提到的url在阿賈克斯,但將提交..........表單提交codeigniter使用ajax

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

怎麼稱爲kickerLogin()?附加到事件? –

+0

控制檯中的任何錯誤? –

+0

直接通過在瀏覽器中調用你的ajax url來檢查,並檢查你的控制器函數是否被調用 –

回答

2

在你的js文件不能使用<?php echo $GLOBALS['base_url']; ?>。然後在你的觀點中包含這個可能工作。而不是<?php echo $GLOBALS['base_url']; ?>在您看來使用<?=base_url()?>

0

如果你的js函數kickerLogin()是你不能使用「」 JS文件,

通過你的URL作爲一個參數,而調用kickerLogin()功能

0

不建議來調用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'); 
}