2012-11-20 42 views
0

我正在使用編程的COdeigniter中的PHP登錄腳本。如果我在此表單中輸入正確的憑證,則會顯示error,而在輸入正確的憑證後,如果我在新選項卡中打開了相同的憑證,則會自動打開它。看起來,一些js問題。任何想法 ?這裏是codeCodeIgniter中的登錄問題

<form method="post" action="#" onsubmit="return validateLogin('loginForm')" name="loginForm"> 
      <table width="100%" cellpadding=0 cellspacing=0> 
      <tr> 
       <td> 
       <b> 
        Username: 
       </b> 
       </td> 
       <td> 
       <input type="text" name="usr" /> 
       </td> 
      </tr> 
      <tr> 
       <td> 
       <b> 
        Password: 
       </b> 
       </td> 
       <td> 
       <input type="password" name="pwd" /> 
       </td> 
      </tr> 
      <tr> 
       <td></td> 
       <td> 
       <input type="submit" value="Login" class="submit" /> 
       </td> 
      </tr> 
      </table> 
     </form> 

功能是

function validateLogin(form) { 
    user = document.forms[form].usr; 
    pwd = document.forms[form].pwd; 
    if(user.value.length==0) 
    { 
    notify('Please enter a valid username', 'error'); 
    user.focus(); 
    hilit('[name = user]'); 
    return false; 
    } 
    else if(pwd.value.length==0) 
    { 
    notify('Please enter a valid password', 'error'); 
    pwd.focus(); 
    hilit('[name = pwd]'); 
    return false; 
    } 
    else 
    { 
    notify('processing.... please wait', 'notice'); 
    dataString = 'user='+user.value+'&pwd='+pwd.value; 
    jQuery.ajax({ 
     type: "POST", 
     data: dataString, 
     url: baseurl+'admin/checkLogin', 
     cache: false, 
     error: function() 
     { 
     notify("An error occurd... please try later", 'error'); 
     }, 
     success: function(html) 
     { 
     if(html == 1) 
     { 
      window.location = baseurl+'admin/home'; 
     } 
     else 
     { 
      notify('Your login details are incorrect!!!', 'error'); 
     } 
     } 
    }); 
    return false; 
    } 
    return false; 
} 

回答

0

你正在一個錯誤的方式 發送到服務器必須是鍵/值對數據發送數據。 {key : value}

修改你的數據在Ajax調用這樣

data : { user : user.value, pwd : pwd.value} 

編輯

更改您的錯誤,從`dataString =處理代碼與此

error:function(xhr,err){ 
    alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status); 
    alert("responseText: "+xhr.responseText); 
} 
+0

您手段 'USER =' + user.value +'&pwd ='+ pwd.value;'這個'data:{user:user.value,pwd:pwd.value}'? –

+0

不是,而是如果'data:dataString,'把這個'data:{user:user.value,pwd:pwd.value},' – Ravi

+0

Nopes,它沒有工作。顯示相同的錯誤,在新標籤中工作相同的憑據。 –