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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:51:21+00:00 2026-06-10T08:51:21+00:00

I have an ajax request in my javascript that is sending data to a

  • 0

I have an ajax request in my javascript that is sending data to a Rails controller. If the controller finds that the data is duplicate of information already in the database, it returns an ‘Unprocessable Entity’ error.

I would like to have a dialog open and ask a user if he is sure he wants to insert the duplicate information. If the user says yes, I’d like to add another key to the data object and retry the request. The key added would be a flag that ignores the duplicate check and inserts the data anyway.

$.ajax({
      url: '/url',
      type: 'post',
      data: this.buildData(),
      success: function() {
        bootbox.alert('Information added', function() {
            Backbone.history.loadUrl();
          }.bind(this)
        );
      }.bind(this),
      error: function(jqXHR, textStatus, errorThrown) {
        if(errorThrown === 'Unprocessable Entity') {
          bootbox.confirm('Do it anyway?', function(confirm) {
              if(confirm) {
                /*Here I want to add another key to the data object and resend the request*/ 
              }
             }.bind(this)
           );
         }  
       }.bind(this)
    });

How would I go about doing this, or better yet, is there a better way of doing what I am trying to accomplish?

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

    First of all I am sure there is some plugin for that.

    But if no plugin is suitable you can always do something like this

    function dispatchAjax( options ){
    
         options = $.extend({},options);
         var data = $.extend({}, this.buildData(), options.data );
         $.ajax({ ... , 
                      error : function( ) { .... 
                                 if ( typeof(options.retry) == "function" ){
                                       var retryFunc = options.retry;
                                       options.retry = null;
                                       options.data = { "extraKey":"extraValue"};
                                       dispatchAjax( options );
                                 }
                 });
    
    }
    

    give me some time to make sure this runs properly and give full code

    Another way you might be interested is using synchronous call. {"async":false} in JQuery’s ajax request.

    I know this might seem to defeat the purpose, however I found it quite useful for server side validation – so it might suite your needs and you won’t have to deal with complicated handlers as I show above, it would simply be something like this :

      var result = dipatchRequest( options, /*async*/  false, /*ignore-duplicates*/ false );
      if ( result.error && confirm(..) ){ 
           dispatchRequest(options, true, true);
      } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this javascript that pulls some data via an ajax request the method
I have an HTML page with a JavaScript code that sends AJAX request. The
I am trying to fake synchronous JavaScript while doing an AJAX request. I have
I have ajax request that do 3 missions: Save Model (DB) Send Email Give
I have an Ajax request that can return more than one valid value, so
I have a AJAX request that will return a string that contains some HTML
I have a Ajax request that fires on clicking a href that is part
I have an Ajax request that comes in to update part of the webpage.
I am sending an AJAX request using javascript to a servlet. The servlet is
Possible Duplicate: AJAX request fails to process $_SESSION variable I have some strange issue

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.