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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:50:58+00:00 2026-06-10T03:50:58+00:00

Following up on my question from the other day, I’ve run into another thing

  • 0

Following up on my question from the other day, I’ve run into another thing that now I’ve spent too many hours banging my head against.

Mostly, I’m having trouble getting the SUCCESS form to submit. I tried this as well:

jQuery form submit

Here’s the code in a semi-functional fiddle:

http://jsfiddle.net/ZcgqV/

Essentially what happens is this:

  1. I bind a method to the form’s submission via onSubmit (rather than click)
  2. On submit, it calls a remote server via jQuery .ajax() call
  3. If the response is “PENDING”, retry every 1s, nine times
  4. On failure, don’t submit the form
  5. On success, submit the form

No matter what I try, I can’t get the form to either submit when I want it to without going into a loop, or not submit immediately while it tries the remote server.

~Frustrated-trying-100-things-that-fail-ly yours…

Here’s the code directly in case you dislike fiddles:

var retries = 0;
var success = false;
var token = "toki wartooth is not a bumblebee";

$(document).ready(function() {
    // Attach the action to the form
    $('#tehForm').attr('onSubmit', 'onsubmit_action(event)');
});

function async(fn) {
    setTimeout(fn, 1000);
}

function pollServer() {
    $.ajax({
        type: "POST",
        cache: "false",
        url: "/remoteCall",
        dataType: "json",
        data: {
            ref_token: token
        }
    }).done(function(data, code, jqXHR) {

        switch (data.status) {
        case "SUCCESS":
            alert("Success");
            success = true;

            // --> HERE IS WHERE I WANT THE FORM TO SUBMIT <--

            break;

        case "PENDING":
            if (retries < 9) {
                retries += 1;
                async(function() {
                    pollServer();
                });
            } else {
                alert("Failed after 9 tries");
            }
            break;

        case "ERROR":
            alert("Error");
            break;

        default:
            alert("Some kind of horrible error occurred");
            break;
        }

    }).fail(function(jqXHR, textStatus) {
        var statusCode = jqXHR.status;
        alert("Request failed: " + statusCode + " " + textStatus);
    });

}

function onsubmit_action(event) {
        pollServer();
        if (success === false) {
            // RETURN FALSE DIDN'T WORK, SO I FOUND THIS
            event.preventDefault();
        }
}​

EDIT:

Again, the real problem here is that I stop submission of the form. On SUCCESS, I want the form to submit. Currently if I use .submit() in SUCCESS, the AJAX is called again, starting the process over. What I want is the ACTION of the FORM to fire on SUCCESS only.

  • 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-10T03:51:00+00:00Added an answer on June 10, 2026 at 3:51 am

    Trying to use as much of the original code as possible; here is a solution:

    Post form with post back
    http://jsfiddle.net/tpm7v/4/

    Post form via Ajax
    http://jsfiddle.net/tpm7v/5/

        var retries = 0,
        token = "toki wartooth is not a bumblebee",
        sendRequest,
        handelResponse,
        postFormToServer,
        $theForm = $('#tehForm');
    
    $(document).ready(function() {
        // Attach the action to the form
        $theForm.bind('submit', onsubmit_action);
    });
    
    sendRequest = function() {
        $.ajax({
            type: "POST",
            cache: "false",
            url: "/remoteCall",
            dataType: "json",
            data: {
                ref_token: token
            },
            success: handelResponse
        });
    };
    
    postFormToServer = function() {
        $.ajax({
            type: "POST",
            cache: "false",
            url: "/remoteCallToTakFormData",
            dataType: "json",
            data: $form.serialize(),
            success: function() {
                alert('success!');
            }
        });
    };
    
    handelResponse = function(data, code, jqXHR) {
        switch (data.status) {
            case "SUCCESS":
                postFormToServer();
                break;
    
            case "PENDING":
                if (retries < 9) {
                    retries += 1;
                    setTimeout(sendRequest , 1000);
                } else {
                    alert("Failed after 9 tries");
                }
                break;
    
            case "ERROR":
                alert("Error");
                break;
    
            default:
                alert("Some kind of horrible error occurred");
                break;
            }
    };
    
    function onsubmit_action(evt) {
        evt.preventDefault();
        sendRequest();
    }
    ​
    ​
    

    Keep in mind I am going off the code your provided. You should be able to port this to work with your actual implementation. You may also want to try something like https://github.com/webadvanced/takeCommand to help clean up all the Ajax calls.

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

Sidebar

Related Questions

Following this question, it seems that it is possible to open a file from
I used the code from the following question to insert a YouTube video into
I am revising for a Database course and I have the following question from
Whilst doing exam revision I am having trouble answering the following question from the
While studying for a Functional Programming exam, I came across the following question from
I have downloaded sample code from Apple Center.I also have gone through following question:
Following from these question Subset sum problem and Sum-subset with a fixed subset size
Following on from this question , I am interested in finding out how you
following on from this question (Developing to an interface with TDD), I'm still having
Following on from this question...I'm trying to unit test the following scenario: I have

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.