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

  • Home
  • SEARCH
  • 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 7020441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:19:08+00:00 2026-05-27T23:19:08+00:00

I have the following action: $(‘.sub_outworker’).live(‘click’, function() { var input = $(this); var current_div

  • 0

I have the following action:

   $('.sub_outworker').live('click', function() {

                var input = $(this);
                var current_div = input.parents('div.report');
                var current_div_id = current_div.attr('id');
                var replace_div = current_div.children('div').first();
                var submission = submit_form(input, replace_div);
                var i = 0;
}

The submit_form() function looks like this:

function submit_form(input, replace_div) {
            var form = input.parents('form');

            loading_gif(replace_div);

             $.ajax({
                type: 'POST',
                url: form.attr('action'),
                data: 'ajax=true&' + form.serialize(),
                success: function(data) {
                    get_json();

                    if(data == 'success') {
                        return 'success';
                    }
                    else {
                        return 'failed';
                    }
                }
            });
        }

I want to check whether submission == failed and if it does run submit_form again (ie. give the function a second chance to work – mainly because it occasionally fails validation due to a mismatch in tokens). I’m not sure how to go about this though!

  • 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-27T23:19:09+00:00Added an answer on May 27, 2026 at 11:19 pm

    If you just want to run it one more time, the easiest (and IMO cleanest) way might be to use deferred objects [docs]:

    function submit_form(input, replace_div) {
        var deferred = new $.Deferred();
        var form = input.parents('form');
    
        loading_gif(replace_div);
    
         $.ajax({
            type: 'POST',
            url: form.attr('action'),
            data: 'ajax=true&' + form.serialize(),
            success: function(data) {
                get_json();
    
                if(data == 'success') {
                    deferred.resolve(data);
                }
                else {
                    deferred.reject(data);
                }
            }
        });
    
        return deferred;
    }
    

    Then you can do:

    var request = submit_form(input, replace_div);
    request.fail(function() {
        submit_form(input, replace_div);
    }).done(function() {
       // request was successful, do something
    });
    

    Deferred objects provide great flexibility with asynchronous calls and let you easily decouple code. Of course if you want to see the repeated attempt to make the Ajax call as a “feature” of the submit_form function or if you want to repeat it more than once, then @Matt’s answer seems to be the better way.

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

Sidebar

Related Questions

I have the following action. I can hit this with /basket/address?addressId=123 However i wonder
I have the following controller action: public ActionResult Edit(int id) { var news =
I have the following: $(.action_btn).click(function(){ } echo '<a class=saved action_btn x mid=' . $itemId['MID2']
I have the following Action method. public ActionResult Action() { var model = new
I have the following Action Method: [HandleFtmsError] public ActionResult PerformanceChart(ChartViewModel chart) { var x
On my controller I have the following Action: public function indexAction() { $teamDao =
I have the following controller action and test. I'm new to testing with Shoulda
I have the following index action: class ExpensesController < ApplicationController def index() @expenses =
I have the following code in action script 3: async.addResponder(new Responder(result, defaultFaultHandler)); result is
I have following code: public static void ProcessStep(Action action) { //do something here if

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.