2012-05-24 7 views
1

아약스 양식 제출과 관련된 문제가 있습니다. 동적으로 양식을 제출하고 처리하기 위해 서버 측에서 PHP를 사용하고 있습니다. 이것은 아작스 성공 함수입니다. 사용자가 유효한 경우아약스 양식 요청

$.ajax({ 
         type: "POST", 
         url: "register.php", 
         data: "uname="+uname+"&eid="+eid+"&pwd="+pass+"&cpwd="+cpass+"&country="+coun+"&contact="+contact, 
         dataType: "html", 
         success: function(data){ 
          if(data!="error") 
          { 
           //alert(data); 
           $("#user_status", window.parent.document).html("Welcome "+data+"&nbsp;&nbsp;|&nbsp;&nbsp;<a href='forum/logout.php'>Logout</a>"); 
           if(window.parent.document.getElementById('post_user_name')) 
            $("#post_user_name", window.parent.document).html(msg); 
           parent.$.fancybox.close(); 
          } 
          if(data=="error") 
          { 
           //alert(data); 
           $("#status").html("<span><center><font class='formright err_msg' style='width:176px;'>The user is already register with us.</font><center></span>"); 
           return false; 
          } 

지금 그는에 기록되고 국지적 유효한 부분이 잘 작동 "이미 존재합니다"와 같은 f를하지 오류가있을 가지고 있지만 무효을 위해 나는 PHP 파일에서 오류를 반환 하지만 여전히 내 오류 메시지가 표시되지 않습니다 그냥 오류가 내 양식 (JQuery와 fancybox) PHP 코드 fancybox를 사용하고있는 screen.I에 인쇄되어

 if($_POST['pwd']==$_POST['cpwd']) 
      { 
       $username = $_POST['uname']; 
       $email  = $_POST['eid']; 
       $password = md5($_POST['pwd']); 
       $cpassword = $_POST['cpwd']; 
       $contact_no = $_POST['contact']; 
       $country = $_POST['country']; 

       $cnt  =  $checkUser['cnt']; 

       if($cnt!=0) 
       { 
        echo "error"; 
        //exit; 
        /*$_SESSION['error_msg'] = 'Email Address already exists'; 
        redirect_to_link("index.html");*/ 

       } 
       else 
       { 
        //echo "entered here"; 
        $userArray = array(); 
        //$user = return_post_value($_POST['uname']); 
        $userArray['uname'] = return_post_value($_POST['uname']); 
        $userArray['email'] = return_post_value($_POST['eid']); 
        $userArray['password'] = md5(return_post_value($_POST['pwd'])); 
        $userArray['contact_no'] = return_post_value($_POST['contact']); 
        $userArray['country'] = return_post_value($_POST['country']); 

        //print_r($userArray); 
        //exit; 
        $userObj->addUserValue($userArray); 
        $_SESSION['username']= $userArray['uname'];    
        echo $userArray['uname']; 
            // return $user; 
       } 

에코 $ userArray [ 'UNAME'입니다 ]; 부분은 작동하지만 에코 "오류"가 아닙니다. 방화 광 응답 헤더에 체크되어 반환 된 오류 단어를 볼 수 있습니다. 누구든지 그것에 불을 붙일 수 있습니까?
감사

+0

당신은 자바 스크립트에서 데이터에 대한 경고를 할 수 있습니다. 그리고 왜 당신은 거짓을 반환하고 있습니까? if (data == 'error') 조건? –

+0

그래, 그걸 시도했지만 거기에 도달하지 못한다. 여전히 (데이터! = "오류") 루프에 들어간다! : P 나는 ** http://www.proptiger.com/ 헤더 ** 등록 ** 링크 (양식)와 비슷한 것을하려고합니다. 감사합니다. – KillABug

+0

성공 함수의 데이터 값을 출력하고 여기에 출력을 제공 할 수 있습니까? –

답변

1

사용이 ($가. (데이터를 트림 = "오류"!)) 경우

을 비교 그리고 만약을 위해 다시 확인하지 않는 ($입니다. 데이터 (트림) == "오류")

당신이 응답을 얻을 후

사용

if($.trim(data)!="error") 
{ 
// 
} 
else{ 
// 
} 
+0

Worked !!!!! Gem ** subirkumar **. 너무 감사합니다. ** Codemaster Gabriel **. 또한 서버 측의 공백을 제거 할 수 없습니다.이 'stripslashes'를 추가하여 공백을 없애고, 그러나 일하지 않았다!! 그리고이 예제를 언급 한 부분도 그 부분을 가지고 있지 않습니다 !! 그러면 이유가 무엇입니까?이 점에 대해 의견을 말하고 조금 자세히 설명해 주시겠습니까? 덕분에 – KillABug

+0

stripslashes는 서버 측의 공백을 제거하지 않습니다. trim(), ltrim(), rtrim()은 서버 측에서도 공백을 제거하는 데 사용할 수있는 함수입니다. –

+0

PHP 닫기 태그 뒤에 빈 공간이있는 것 같습니까?> 확인하십시오. –