在不刷新页面的情况下使用jquery重置表单后无法重新提交表单

时间:2014-06-04 20:58:01

标签: php jquery ajax form-submit reset

我有一个"分享链接"使用ajax提交的表单。提交表单后,它将被隐藏,并显示一个弹出确认框,其中包含指向"再次共享"的链接。如果我点击"再次分享"表单字段被重置,表单再次显示。但是它永远不会第二次提交。

我不认为它是导致问题的Captcha,因为验证码就在那里。无论是否正确输入验证码质询,表格都会提交。有一个蜜罐字段来处理垃圾邮件过滤。

这是我正在使用的jquery

$("#sharethis").submit(function() {
    $('.loading').show(); // display loading animation
    $('#sharethis').fadeOut('slow'); // hide the form after submission
    $('html, body').animate({scrollTop: 0}, 500);
    //Do the AJAX post
    $.post($("#sharethis").attr("action"), $("#sharethis").serialize(), function(data){
        //do stuff here...
          $('.loading').fadeOut('slow'); //hide the loading animation after successful post
          $('#share-confirmation').fadeIn('slow'); // show the popup with link to share again
    });
    //Important. Stop the normal POST

    return false;
});
$('#share-confirmation .back-link').click(function(e){
  e.preventDefault(); // prevent default action of share again link
  $('#share-confirmation').fadeOut('slow'); // hide popup
  $('#sharethis').fadeIn('slow'); // show form
  $('#sharethis')[0].reset(); //reset form fields
});

表格本身:

<div id="share-form" class="form-wrapper">
<div class="close-button share-toggle"></div>
<div class="loading"></div> 
<div id="share-confirmation" class="done">
<div class="form-text">Email Sent!</div>
<a href="<?php print $node_url; ?>" class="back-link form-text">Share again</a>
<a href="?q=advanced-property-search" class="share-link form-text">Go Back to Offerings</a>
</div>
<div id="share-error"><span class="form-text">Email could not be sent</span></div>
<form id="sharethis" name="sharethis" action="sites/all/themes/greysteel/mailer/share-listing.php" method="post">
<label for="shareto">To Email:</label>
<input type="email" name="shareto" class="form-text" size="30" maxlength="128" required/>
<label for="sharefrom">From Name:</label>
<input type="text" name="sharefrom" id="sharefrom" class="form-text" size="30" maxlength="128" required/>
<label for="sharefromemail">From Email</label>
<input type="email" name="sharefromemail" class="form-text" size="30" maxlength="128" required/>
<div id="sendcopy" class="form-text">Send me a copy</div>
<input type="checkbox" name="sharecc" id="sharecc" value="1" />
<label for="sharemsg">Message:</label>
<input type="hidden" name="sharelisttitle" value="<?php print $title; ?>" />
<textarea name="sharemsg" class="form-textarea"></textarea>
<label for="shareurl">URL:</label>
<div class="form-text">http://greysteel.com<?php print $node_url; ?></div>
<input type="hidden" name="shareurl" value="http://greysteel.com<?php print $node_url; ?>" />
<?php if(isset($content['field_email_property_logo'])): ?>
<input type="hidden" name="sharelogo" value="<?php print file_create_url($node->field_email_property_logo['und'][0]['uri']); ?>" />
<?php else: ?>
<input type="hidden" name="sharelogo" value="<?php print file_create_url($node->field_property_image['und'][0]['uri']); ?>" />
<?php endif; ?>
<?php if(isset($content['field_property_memorandum'])): ?>
<input type="hidden" name="ca-agreement" value="<?php print render($content['field_property_memorandum']['#items']['0']['value']); ?>" />
 <?php endif; ?>
<input type="hidden" name="test" class="test-field" />
<div id="recaptcha1" class="captcha">

<img id="captcha" src="sites/all/themes/greysteel/securimage/securimage_show.php" alt="CAPTCHA Image" />
  <input type="text" name="captcha_code" size="10" maxlength="6" /><br>
  <a href="#" class="form-text" onclick="document.getElementById('captcha').src = 'sites/all/themes/greysteel/securimage/securimage_show.php?' + Math.random(); return false">[ Different Image ]</a>
</div> 
<input type="submit" id="share-submit" name="submit" value="Send" class="form-submit" /> 
</form>
<!--[if IE]><iframe class="cover" src="about:blank"></iframe><![endif]-->
</div>

1 个答案:

答案 0 :(得分:0)

如果替换此

怎么办?
$("#sharethis").submit(function() {

由此

$(document).on('submit', '#sharethis', function(){
在你的jQuery中?