Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9108273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:46:11+00:00 2026-06-17T02:46:11+00:00

jquery ajax form: loading image only and doesnt stop and success message not working

  • 0

jquery ajax form: loading image only and doesnt stop and success message not working

this is my contact form

            <form method="post" action="" class="comments-form" id="contactform" />

                <p class="input-block">
                    <label for="name">Name:</label>
                    <input type="text" name="name" id="name" />
                </p>

                <p class="input-block">
                    <label for="email">E-mail:</label>
                    <input type="text" name="email" id="email" />
                </p>

                <p class="input-block">
                    <label for="message">Message:</label>
                    <textarea name="message" id="message" cols="30" rows="10"></textarea>   
                </p>

                <p class="input-block">
                    <button class="button default" type="submit" id="submit">Submit</button>
                </p>

            </form>

and this is my jquery ajax function that is not working

(function() {

    if($('#contactform').length) {

        var $form = $('#contactform'),
        $loader = '<img src="images/preloader.gif" alt="Loading..." />';
        $form.append('<div class="hidden" id="contact_form_responce">');

        var $response = $('#contact_form_responce');
        var $p
        $response.append('<p></p>');

        $form.submit(function(e){

            $response.find('p').html($loader);

            var data = {
                action: "contact_form_request",
                values: $("#contactform").serialize()
            };

            //send data to server
            $.post("php/contact-send.php", data, function(response) {

                response = $.parseJSON(response);

                $(".wrong-data").removeClass("wrong-data");
                $response.find('img').remove();

                if(response.is_errors){

                    $response.find('p').removeClass().addClass("error type-2");
                    $.each(response.info,function(input_name, input_label) {

                        $("[name="+input_name+"]").addClass("wrong-data");
                        $response.find('p').append('Please enter correctly "'+input_label+'"!'+ '</br>');
                    });

                } else {

                    $response.find('p').removeClass().addClass('success type-2');

                    if(response.info == 'success'){

                        $response.find('p').append('Your email has been sent!');
                        $form.find('input:not(input[type="submit"], button), textarea, select').val('').attr( 'checked', false );
                        $response.delay(1500).hide(400);
                    }

                    if(response.info == 'server_fail'){
                        $response.find('p').append('Server failed. Send later!');
                    }
                }

                // Scroll to bottom of the form to show respond message
                var bottomPosition = $form.offset().top + $form.outerHeight() - $(window).height();

                if($(document).scrollTop() < bottomPosition) {
                    $('html, body').animate({
                        scrollTop : bottomPosition
                    });
                }

                if(!$('#contact_form_responce').css('display') == 'block') {
                    $response.show(450);
                }

            });

            e.preventDefault();

        });             

    }

})();

and this is my contact-send.php that saves the message in my database.

require_once "../includes/database.php";
    $cname=$_POST['name'];
    $cemail=$_POST['email'];
    $cmessage=$_POST['message'];
    $date=date("Y-m-d");    
            $sql = "INSERT INTO messages (sendername,senderemail,message,datesent) VALUES (:name,:email,:message,:date)";
            $qry = $db->prepare($sql);
            $qry->execute(array(':name'=>$cname,':email'=>$cemail,':message'=>$cmessage,':date'=>$date));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:46:13+00:00Added an answer on June 17, 2026 at 2:46 am

    I think your issue is here:

    $.post("php/contact-send.php", data, function(response) {
    
                response = $.parseJSON(response);
           //--^--------------------------------------missing '$' 
    
                $(".wrong-data").removeClass("wrong-data");
                $response.find('img').remove();
          //----^------------------------------------used the '$' for other codes
    

    try to put a $ here and see if this solves the issue:

    $response = $.parseJSON(response);
    

    and if you are getting some ajax errors plz mention it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Jquery Mobile page into which I'm loading a form via AJAX.
How to create jQuery + ajax form without refresh? This is my controller and
I'm doing a jQuery AJAX post like this: var form = $(#formid); form.submit(function() {
I'm processing subscription form with jQuery/ajax and need to display results with success function
I have the following jQuery code: $.ajax({ type: POST, url: /search, data: $(form).serialize(), success:
I'm using jQuery to show a success message after a form is submitted. The
I'm using Jquery Ajax Form to upload files, which works well in Chrome and
I am having some issues with multiple form submissions with a jQuery/ajax form. I
Possible Duplicate: jQuery AJAX submit form I have a form on a page A,
I am using JQUERY .ajax() to send serialized form data to MySQL using PHP.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.