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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:17:20+00:00 2026-05-25T15:17:20+00:00

I want to intercept a form, check for a condition and if it exists,

  • 0

I want to intercept a form, check for a condition and if it exists, prevent the default action. Otherwise, I want to pretend no such interception took place. The JavaScript looks something like this.

$("form").submit(function (event)
{
    $.ajax
    ({
        url: $(this).attr("action"),

        type: $(this).attr("method"),

        data: $(this).serialize(),

        dataType: "html",

        async: false,

        success: function (response)
        {
            if (foo in response) // This is just pseudo code.
            {
                event.preventDefault();

                // bar
            }
        }
    });
});

The problem is that the form is being submitted twice if foo is not found in response and I can’t figure out why. I can assure you that it is a JavaScript issue. If I disable this progressive enhancement, everything works as designed.

EDIT: Adding return false at the end of the code is absolutely incorrectly. I stated that if foo is not found in response I want to pretend no such interception took place. That means I want the page to refresh and do whatever it was going to do.

I am already preventing the default event under very specific circumstances.

EDIT: sillyMunky and alex have touched on my issue. There is definitely a flaw in my design that I’m trying to resolve.

EDIT: I’m looking for help and I have provided code. Downgrading questions and answers without providing feedback is just plain rude.

  • 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-25T15:17:21+00:00Added an answer on May 25, 2026 at 3:17 pm

    It appears you are submitting the form via XHR. If so, just call event.preventDefault() at the top of your submit() function.

    If you want to natively resubmit the form later in the success callback, call the form’s native submit() event, i.e. $('form')[0].submit() (which won’t trigger jQuery’s submit() which would cause an infinite loop because of the rehandling of the condition).

    Using async: false will lock the browser before the request has finished. Don’t do that.

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

Sidebar

Related Questions

In my Manager controller's add action I want to intercept the form submission, perform
Before starting my application (on Form Load) I want to check and ensure that
I have form with MainMenu and I want to intercept when the user selects
Has anyone found a way to intercept the default Form::postLink() forms with Jquery? I
I want to intercept a request in a filter/servlet and add a few parameters
I want to intercept long press on UITextview, but don't want to disable the
I just want to intercept raw data (hex)--headers and all--sent to a port, and
I'm starting a Stack Exchange site and I want to be able to intercept
I want to check whether internet connection is enable on the start of the
I just started adding JS-validation to a signup form and I want the username

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.