dtgr6303 2012-11-02 15:00
浏览 29

Jquery ajax没有来自php的回复

I have a form that is in a modal dialog box. When I submit the form I am not getting the response from php. I know that the form and script is working because I can run them outside the dialog and everything works.

Here is my form html code:

 <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>

Here is the php process file. Please remember this works fine in it is submitted in it's own browser window.

<?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.";
  }
}

?>

Here is the js code that is included in the header file:

         <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>

and lastly I will include the query method from the class file:

              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() );
            }
          }

Thank you for your help!!

  • 写回答

4条回答 默认 最新

  • duancifu6769 2012-11-02 15:06
    关注

    Why not send the data like this as well?

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

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。