2012-11-20 3 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}

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

편집

변경`dataString =에서이

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

당신 수단으로 코드를 오류 처리와 같은 Ajax 호출에 데이터를 수정하는 '사용자 =' + user.value + '& pwd ='+ pwd.value;'를 this 'data : {user : user.value, pwd : pwd.value}'로 변경 하시겠습니까? –

+0

대신'data : dataString,'이'data : {user : user.value, pwd : pwd.value} '를 넣지 않으면 안된다. – Ravi

+0

Nopes가 작동하지 않는다. 새 탭에 동일한 오류가 표시되어 동일한 자격 증명이 작동했습니다. –