Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 按“提交”时,加载图标将保持加载状态_Javascript_Jquery_Html_Ajax_Forms - Fatal编程技术网

Javascript 按“提交”时,加载图标将保持加载状态

Javascript 按“提交”时,加载图标将保持加载状态,javascript,jquery,html,ajax,forms,Javascript,Jquery,Html,Ajax,Forms,我们的移动表单有点小问题 我有一个移动表单,我们的用户使用它向我们发送联系请求。我们遇到的问题是,当他们按下submit时,即使表单已提交且数据已接收,加载图标仍会继续运行。我们仍然可以得到数据,但它看起来不太专业,因为用户不知道表单是否已经过期,可能会重新提交web表单,导致重复提交 非常感谢您事先的帮助 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta na

我们的移动表单有点小问题

我有一个移动表单,我们的用户使用它向我们发送联系请求。我们遇到的问题是,当他们按下submit时,即使表单已提交且数据已接收,加载图标仍会继续运行。我们仍然可以得到数据,但它看起来不太专业,因为用户不知道表单是否已经过期,可能会重新提交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>

租用
你的名字:
您的电子邮件:
事件描述
$('form')。提交(函数(e){
var vals=$(this.serialize();
$.post('thankyou2.php',VAL,函数(数据){
});
e、 预防默认值();
});

您所做的并不是指定在成功或错误时要做什么

试试下面的方法

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

}))

你是指浏览器的加载图标还是你实现的图标?@Chris Campbell:你能发布一个工作演示吗?一直在加载的是jquery微调器