ajax没有发布表单变量

时间:2016-07-19 15:03:27

标签: javascript php jquery ajax

我有一个使用AJAX将一些变量发布到PHP处理程序的表单。现在,奇怪的是在同一页面上我有其他几种正常工作的形式(并且不仅仅是回显变量)。那些工作正常,我做的事情是一样的,但由于某种原因,这个不会。你能发现错误吗?此外,实际请求是成功的,因为如果我在PHP中放置了一些回声,它会在成功回调中返回到console.log。

形式:

<div class="doctor_register" >
                    <form id = 'doctor_register' method ='post'>
                    <input type ='hidden' name ='type' value='doctor'>
                    <input type ='hidden' name='act' value='create'>
                <table>
                    <tbody>
            <br></br>

                    <tr>
                        <td><input type="text" name ='first_name' size='8' placeholder='First Name'/></td>
                         <td><input id ='last_name'type="text" name = 'last_name' size='8' placeholder ='Last Name'/></td>
                    </tr>
                    <br></br>

                    <tr>
                        <td><input class='register_inputs' type="text" name='user_name' placeholder='Username' size='14'/></td>

                    </tr>

                    <tr>
                        <td><input class='register_inputs' type="text" name='email' placeholder='Email'size='14' /></td>

                    </tr>
                <tr></tr>
                    <tr>
                        <td><input class='register_inputs' type="password" name='user_password1' placeholder='Password' size='14' /></td>
                    </tr>
        <tr></tr>
                    <tr>
                        <td><input class='register_inputs' type="password" name='user_password2' placeholder='Confirm Password' size='14' /></td>

                    </tr>
                                <td>
    <table>
    <tr>
        <td><img id="captcha_image" src="modules/captcha/securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"></td>
        <td>
            <a href="modules/captcha/securimage_play.php"><img style="padding:0px; margin:0px; border:0px;" id="captcha_image_play" src="modules/captcha/images/audio_icon.gif" title="<?php echo _PLAY; ?>" alt="<?php echo _PLAY; ?>" /></a><br />
            <img style="cursor:pointer;padding:0px;margin:0px;border:0px;" id="captcha_image_reload" src="modules/captcha/images/refresh.gif" style="cursor:pointer;" onclick="document.getElementById('captcha_image').src = 'modules/captcha/securimage_show.php?sid=' + Math.random(); appSetFocus('frmReg_captcha_code'); return false;" title="<?php echo _REFRESH; ?>" alt="<?php echo _REFRESH; ?>" />
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="text" id="frmReg_captcha_code" name="captcha_code" style="width:148px;" maxlength="20" value="" autocomplete="off" />
        </td>
    </tr>
    </table>
</td>
            <tr></tr>
                    <tr>
                        <td><input type='submit' name ='submit' ></td>
                        <td><a href="#" class="back_doctor_login">Back</a></td>
                    </tr>
                </table>
                </form>
            </div>

JavaScript的:

   <script>
     $('#doctor_register').on("submit",function(){

     frmReg = document.getElementById("doctor_register");

     if(frmReg.first_name.value == "")          { alert("<?php echo _FIRST_NAME_EMPTY_ALERT; ?>");  frmReg.first_name.focus(); return false;
    }else if(frmReg.last_name.value == "")     { alert("<?php echo _LAST_NAME_EMPTY_ALERT; ?>"); frmReg.last_name.focus(); return false;
    }else if(frmReg.email.value == "")         { alert("<?php echo _EMAIL_EMPTY_ALERT; ?>"); frmReg.email.focus(); return false;
    }else if(!appIsEmail(frmReg.email.value))  { alert("<?php echo _EMAIL_VALID_ALERT; ?>"); frmReg.email.focus(); return false;
    }else if(frmReg.user_name.value == "")     { alert("<?php echo _USERNAME_EMPTY_ALERT; ?>"); frmReg.user_name.focus(); return false;
    }else if(frmReg.user_password1.value == ""){ alert("<?php echo _PASSWORD_IS_EMPTY; ?>"); frmReg.user_password1.focus(); return false;
    }else if(frmReg.user_password2.value == ""){ alert("<?php echo _CONF_PASSWORD_IS_EMPTY; ?>"); frmReg.user_password2.focus(); return false;
    }else if(frmReg.user_password1.value != frmReg.user_password2.value){ alert("<?php echo _CONF_PASSWORD_MATCH; ?>"); frmReg.user_password2.focus(); return false;
    }else if(frmReg.captcha_code.value == "")  { alert("<?php echo _IMAGE_VERIFY_EMPTY; ?>"); frmReg.captcha_code.focus(); return false;
    }else {

    $.ajax({
    type : 'POST',
    url: '../doctor/handlers/handler_ajax_handler.php',
    data: $('#doctor_register').serialize,
    success: function(e){ console.log(e);},
    error: function(){ alert('error');}

   });
     }
     });
  </script>

PHP:

print_r($_POST);

0 个答案:

没有答案