You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

网站表单提交后按钮持续显示‘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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 19:00:27