网站表单提交后按钮持续显示‘Sending...’,无法触发成功/错误提示的问题求助
网站表单提交后按钮持续显示‘Sending...’,无法触发成功/错误提示的问题求助
我在自己的网站上做了一个带JS的表单,提交的时候按钮一直显示‘Sending ...’,也不弹出成功提示,但表单数据其实已经成功收到了。我刚接触JS,实在搞不清哪里出问题了,麻烦大家帮忙看看!
提交按钮点击后就一直停留在‘Sending ...’状态,既不跳转到成功操作也不显示错误提示,但后台确实能收到表单信息。
下面是我使用的JS代码:
$(function() { function after_form_submitted(data) { if($.trim(data.result) == 'success') { $('form#reused_form').hide(); $('#success_message').show(); $('#error_message').hide(); } else { $('#error_message').append('<ul></ul>'); jQuery.each(data.errors,function(key,val) { $('#error_message ul').append('<li>'+key+':'+val+'</li>'); }); $('#success_message').hide(); $('#error_message').show(); //reverse the response on the button $('button[type="button"]', $form).each(function() { $btn = $(this); label = $btn.prop('orig_label'); if(label) { $btn.prop('type','submit' ); $btn.text(label); $btn.prop('orig_label',''); } }); }//else } $('#reused_form').submit(function(e) { e.preventDefault(); $form = $(this); //show some response on the button $('button[type="submit"]', $form).each(function() { $btn = $(this); $btn.prop('type','button' ); $btn.prop('orig_label',$btn.text()); $btn.text('Sending ...'); }); var formdata = new FormData(this); $.ajax({ type: "POST", url: 'handler.php', data: formdata, success: after_form_submitted, dataType: 'json' , processData: false, contentType: false, cache: false }); }); });
备注:内容来源于stack exchange,提问作者Swot Cons
相关产品推荐
相关产品推荐

