2012-11-02 5 views
0

모달 대화 상자에있는 양식이 있습니다. 양식을 제출하면 PHP에서 응답을 얻지 못하고 있습니다. 폼과 스크립트는 대화 상자 밖에서도 실행할 수 있고 모든 것이 작동하기 때문에 작동한다는 것을 알고 있습니다.Jquery ajax PHP에서 응답이 없습니다

다음
<div id="add_user"> 
     <form action="resetProcess.php" method="post"> 
      <input type="hidden" name="action" value="Reset Password" /> 
      <table width="385" border="0" cellspacing="0" cellpadding="3"> 
      <tr> 
       <td colspan="3"> 
       </td> 
       </tr> 
      <tr> 
       <td width="191" align="right"><label for="firstname2">First name *</label></td> 
       <td width="194" colspan="2"><input type="text" name="firstname" id="firstname2" value="" /></td> 
       </tr> 
      <tr> 
       <td align="right"><label for="lastname2">Last name *</label></td> 
       <td colspan="2"><input type="text" name="lastname" id="lastname" value="" /></td> 
       </tr> 
      <tr> 
       <td align="right"><label for="email2">Email address *</label></td> 
       <td colspan="2"><input type="text" name="email" id="email" value="" /></td> 
       </tr> 
      <tr> 
       <td colspan="3" style="padding-top:20px;"> 
       <input type="submit" name="action1" id="requestButton" value="Get Email" /></tr> 
      </table> 
     </form> 

</div> 

는 PHP 프로세스 파일입니다

여기 내 양식의 HTML 코드입니다. 이것이 브라우저 창에 제출되면 잘 동작한다는 것을 기억하십시오. 여기

<?php 
    // Required files 
    include("includes/common.inc.php"); 
    require_once("users.class.php"); 

    session_start(); 

// check if the reset password form has been submitted. 
if (isset($_POST["action1"]) and $_POST["action"] == "Reset Password") {  

     $user = new User(array(
     "firstname" => isset($_POST["firstname"]) ? preg_replace("/[^ \-\_a-zA-Z0-9]/", "", $_POST["firstname"]) : "",     
     "lastname" => isset($_POST["lastname"]) ? preg_replace("/[^ \-\_a-zA-Z0-9]/", "", $_POST["lastname"]) : "", 
     "email" => isset($_POST["email"]) ? preg_replace("/[^ \-\_a-zA-Z0-9]@/", "", $_POST["email"]) : "", 

    )); 

$existingUser = User::getByEmailAddress($user->getValue("email")); 

    if ($existingUser) { 
    var_dump($existingUser); 
    echo "Success!! Your Request has been sent!"; 
    } else { 
    echo "That email address does not match anyone in our system. Please go back and re-enter your information."; 
    } 
} 

?> 

는 헤더 파일에 포함 된 JS 코드 :

  <script> 
// increase the default animation speed to exaggerate the effect 
$.fx.speeds._default = 1000; 
$(function() { 
    $("#dialog").dialog({ 
     autoOpen: false, 
     show: "fade", 
     hide: "fade", 
     width: "400px", 
    }); 

    $("#reset-form").click(function() { 
     $("#dialog").dialog("open"); 
     return false; 

    }); 

    // Hide Form error labels 
    $('.error').hide(); 

    $('#requestButton').click(function(e){ 
     e.preventDefault(); 
     var firstname = $('#firstname').val(); 
     if (firstname == "") { 
      $('label#firstname_error').show(); 
      $('label#firstname').focus(); 
      return false; 
     } 
     var lastname = $('#lastname').val(); 
     if (lastname == "") { 
      $('label#lastname_error').show(); 
      $('label#lastname').focus(); 
      return false; 
     } 
     var email = $('#email').val(); 
     if (email == "") { 
      $('label#email_error').show(); 
      $('label#email').focus(); 
      return false; 
     } 
     var dataString = 'firstname=' + firstname + '&lastname=' + lastname + '&email=' + email; 

     // ajax call 
     $.ajax({ 
      type: "POST", 
      url: "resetProcess.php", 
      data: dataString, 
      success: function(result){ 
       //$("#passRequest").fadeOut(500, function(){ 
        console.log("Result: " + result); 
       //}); 
      }, 
     });  
     return false; 
    }); 

    }); 
    </script> 

을 그리고 마지막으로 나는 클래스 파일에서 쿼리 방법이 포함됩니다 :

   public static function getByEmailAddress($email) { 
      $conn = parent::connect(); 
      $sql = "SELECT * FROM " . TBL_USERS . " WHERE email = :email"; 

      try { 
       $st = $conn->prepare($sql); 
       $st->bindValue(":email", $email, PDO::PARAM_STR); 
       $st->execute(); 
       $row = $st->fetch(); 
       parent::disconnect($conn); 
       if ($row) return new User($row); 
      } catch (PDOException $e) { 
       parent::disconnect($conn); 
       die("Query failed: " . $e->getMessage()); 
      } 
      } 

을 주셔서 감사를 당신의 도움!!

+1

대신에 var_dump - 에코를 사용하십시오 –

답변

0

이렇게 데이터를 보내지 않는 이유는 무엇입니까?

$.ajax({ 
    type: "POST", 
    url: "resetProcess.php", 
    data: { 
     'firstname': firstname, 
     'lastname': lastname, 
     'email': email 
    }, 
    success: function(result) { 
     //$("#passRequest").fadeOut(500, function(){ 
     console.log("Result: " + result); 
     //}); 
    }, 
});​ 
+0

여러분 모두에게 감사드립니다 !! – REF

0

실제로 요청을 받고 있지만 게시를 지정한다고 생각합니다.

var data = { 
    'firstname': firstname, 
    'lastname': lastname, 
    'email': email 
} 

을 또는 당신은 게시 그대로 가져 오기 쿼리 문자열을 떠날 귀하의 방법을 변경하여 Ajax 호출에

대신 문자열이 전달합니다. 필요한 파일이 제대로/inlcuded입니다 필요하면 내가 확인 할

0

,

// Required files 
include("includes/common.inc.php"); 
require_once("users.class.php"); 

때문에 어쩌면 당신은 당신이 아약스없이 다르게 다음 resetProcess.php 파일을 것이다 액세스하는. User 클래스가 실제로 있는지 확인하여 확인할 수 있습니다.

+0

이걸 어떻게 확인 하시겠습니까? – REF

0

문제는 PHP 스크립트가 제출 단추가 전달되었는지 확인하고 다른 숨겨진 필드도 설정했는지 확인하는 것이 었습니다.

// check if the reset password form has been submitted. 

경우

(는 isset ($ _POST [ "조치 1"])와 $ _POST [ "행동"] == "암호 재설정")

는 AJAX POST 요청과 함께 전송되지 않았습니다.

관련 문제