按下提交时,加载图标会继续加载

时间:2014-03-17 09:15:19

标签: javascript jquery html ajax forms

我们的移动表单存在轻微问题

我有一个移动表单,我们的用户可以使用该表单向我们发送联系请求。我们遇到的问题是,当他们按下提交时,即使提交了表单并收到了数据,加载图标也会继续运行。我们仍然可以获得数据,但它看起来不太专业,因为用户不知道表单是否已经消失,并且可以重新提交Web表单,从而导致双重提交

非常感谢您的帮助

  <!DOCTYPE html> 
  <html>
  <head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-  1.0rc1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.js">               </script>
   </head> 


<body> 

  <div data-role="page">

<div data-role="header">
    <h1>Hire </h1>
</div><!-- /header -->

<div data-role="content">   
    <form action="thankyou2.php" method="POST">


        <!--    Wrap Inputs in fieldcontain which will sort out borders and padding, can    cause layout to break   -->
         <div data-role="fieldcontain">
            <label for="firstName"> Your Name: </label>
            <input type="text" name="name" value="" id="firstName" />      <!-- Use id and name values  -->
        </div>  

        <div data-role="fieldcontain">
            <label for="lastName"> Your Email: </label>
            <input type="text" name="email" value="" id="lastName" />     <!--  Use id and name values  -->
        </div>  
      <div data-role="fieldcontain">
            <label for="lastName"> Event Description </label>
        <textarea    rows=7 name=message></textarea> <!--   Use id and name values  -->
        </div>  



        <div data-role="fieldcontain">
            <input type="submit" name="submit" value="Send Request" data-theme="b" />
        </div>

    </form> 
</div>

<div data-role="footer">

</div><!-- /footer -->

  </div>
    <script>

   $('form').submit( function(e) {

    var vals = $(this).serialize();
    $.post( 'thankyou2.php', vals, function (data) {
     });

    e.preventDefault();
});

</script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您正在做的不是指定如何处理成功或错误。

尝试以下

$("#btnId").click(function(e) {  
e.preventDefault();
   //show loading animation

   $.ajax({
   ...
   success:function(data){
      //remove loading animation
   },
   error:function(){//remove loading animation
   }
   });
});

我希望这会有所帮助。

编辑:对不起,我自动将其设为ajax ..对于非ajax方法尝试下一个:

$('#form').submit(function() {
$('#loading_image').show();
$.post('/somepage.htm', function() {
    $('#loading_image').hide();
});

});

相关问题