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 6734483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:53:38+00:00 2026-05-26T10:53:38+00:00

I have code that gets called whenever the form is submitted, this then validates

  • 0

I have code that gets called whenever the form is submitted, this then validates the form via ajax. Now if the validation is successful, how do I submit the form

$('#homeSubscriptionFromSub').submit(function(){    
                var formData = $(this).serialize();
                var formUrl = '/subscriptions/subscribe';

                $.ajax({
                        type: 'POST',
                        url: formUrl,
                        data: formData,
                        success: function(data,textStatus,xhr){
                                if(data == ''){
                                    return true;
                                }else{
                                    $("#subscriptionForm").html(data);
                                }
                        },
                        error: function(xhr,textStatus,error){
                                alert(textStatus);
                        }
                });
                return false;
            });

What I do in the above code, I validate the form server side, now when data is empty it means that it passed the validation test, how can I submit the form when data is empty, I tried return true but this is not working

  • 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-05-26T10:53:39+00:00Added an answer on May 26, 2026 at 10:53 am

    The AJAX call is asynchroneous. Use the submit() method (without arguments) to submit the form. Also, I recommend to use event.preventDefault() to cancel a form submissipn beforehand.

    To not cancel your new request by the same function, a variable is created, to keep track whether the form is valid or not.

    (function(){
        var valid = false;
        $('#homeSubscriptionFromSub').submit(function(e){    
            if(valid){
                valid = false;
                return; //Don't prevent default
            }
            e.preventDefault();
            var formData = $(this).serialize();
            var formUrl = '/subscriptions/subscribe';
    
            $.ajax({
                    type: 'POST',
                    url: formUrl,
                    data: formData,
                    success: function(data,textStatus,xhr){
                            if(data == ''){
                                valid = true;
                                $('#homeSubscriptionFromSub').submit();
                            }else{
                                $("#subscriptionForm").html(data);
                            }
                    },
                    error: function(xhr,textStatus,error){
                            alert(textStatus);
                    }
            });
            return false;
        });
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this method in an exterior class that gets called whenever the charachter
In PHP I have the following code that gets a file submitted through CGI:
I have the following code that gets called after the view loads. It works
I have the following question: I got some code that gets called when an
I have some code in a controller (HomeController.cs) that gets called from a $.get
I have the following code that gets called in didSelectRowAtIndexPath. The issue is, when
I have the following code that gets the first 'name' in an array called
I have some code that gets the current logged in user. userID = request.session.get(_auth_user_id)
I have a code sample that gets a SEL from the current object, SEL
I have a line of code that gets the following error when run through

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.