Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a contact form on my website. After filling out the form and clicking submit, the button gets stuck on sending... BUT I still

I have a contact form on my website. After filling out the form and clicking submit, the button gets stuck on "sending..." BUT I still receive the email. I think it might have something to do with the ajax portion of my code? Any help is apprecitated.

$(function()

{

function after_form_submitted(data)

{

if(data.result == 'success')

{

$('form#reused_form').hide();

$('#success_message').show();

$('#error_message').hide();

}

else

{

$('#error_message').append('

    ');

    jQuery.each(data.errors,function(key,val)

    {

    $('#error_message ul').append('

  • '+key+':'+val+'
  • ');

    });

    $('#success_message').hide();

    $('#error_message').show();

    //reverse the response on the button

    $('button[type="button"]', $form).each(function()

    {

    var $btn = $(this);

    var 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();

    var $form = $(this);

    //show some response on the button

    $('button[type="submit"]', $form).each(function()

    {

    var $btn = $(this);

    $btn.prop('type','button' );

    $btn.prop('orig_label',$btn.text());

    $btn.text('Sending ...');

    });

    $.ajax({

    type: "POST",

    url: 'handler.php',

    data: $form.serialize(),

    success: after_form_submitted,

    dataType: 'json'

    });

    });

    });

    Step by Step Solution

    There are 3 Steps involved in it

    Step: 1

    blur-text-image

    Get Instant Access to Expert-Tailored Solutions

    See step-by-step solutions with expert insights and AI powered tools for academic success

    Step: 2

    blur-text-image

    Step: 3

    blur-text-image

    Ace Your Homework with AI

    Get the answers you need in no time with our AI-driven, step-by-step assistance

    Get Started

    Recommended Textbook for

    Big Data, Mining, And Analytics Components Of Strategic Decision Making

    Authors: Stephan Kudyba

    1st Edition

    1466568704, 9781466568709

    More Books

    Students also viewed these Databases questions