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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:29:06+00:00 2026-05-19T01:29:06+00:00

I have a form on a page that adds new data to a database

  • 0

I have a form on a page that adds new data to a database via jQuery. It works fine, but sometimes the server craps out and I get a 500 (Internal Server Error), but that’s because my server sucks.

The problem is that I sometimes get the server error after the PHP makes the addition to the database, but instead of getting a success message, I get the error, even though the addition has been made. So how should I go about this to make sure the PHP doesn’t add the data if I get the error?

[And yes, I will eventually switch to a new server, but no server is perfect]

Here’s the script:

$.ajax({
  type: "POST",
  url: "/clase/do-add",
  data: $("#add").serialize(),
  dataType: "json",
  timeout: 8000,
  beforeSend: function() {
    var icon = '<p class="loading-add"></p>'; // loading icon
    $('form#add').append(icon);
  },
  success: function(data) {
    if (data.error == true) { // php returns error = true if name is invalid
      alert('Invalid name.');
      $('form#add').find('p').remove();
    } else {
      // make the addition
    }
  },
  error: function () { 
    $('form#add').find('p').remove();
    alert('Error. Try again.');
  }
});
  • 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-19T01:29:07+00:00Added an answer on May 19, 2026 at 1:29 am

    You could wrap you ajax call in a function and “reqest” the function again on error.

    Something linke this:

    jQuery.fn = function yourajaxfunction(){
        $.ajax({
          type: "POST",
          url: "/clase/do-add",
          data: $("#add").serialize(),
          dataType: "json",
          timeout: 8000,
          beforeSend: function() {
            var icon = '<p class="loading-add"></p>'; // loading icon
            $('form#add').append(icon);
          },
          success: function(data) {
            if (data.error == true) { // php returns error = true if name is invalid
              alert('Invalid name.');
              $('form#add').find('p').remove();
            } else {
              // make the addition
            }
          },
          error: function () { 
            $('form#add').find('p').remove();
            // ####### i added this:
            $(this).yourajaxfunction();
            alert('Error. Try again.');
          }
        });
    }
    

    Or you could have a idle function that checks again after some miliseconds before you do run the function again at the error:

    $(this).idle().yourajaxfunction();
    

    Idle function used above:

    jQuery.fn.idle = function(time){
        var o = $(this);
        o.queue(function(){
           setTimeout(function(){
              o.dequeue();
           }, time);
        });
        return o;
    };
    

    But the best thing is to fix the server.. this stuff is just hacks and patches that compensate for another problem: the bad server. 🙂

    So it’s not a good idea for any production scenarios.

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

Sidebar

Related Questions

I would like to have an aspx page that contains something like.... <form id=form1
I have a form on an HTML page with multiple submit buttons that perform
I have a form on a page where the user has inputs to edit
I have a simple form on a view page, implemented as a user control,
I have a Drupal module page where I am populating a form with a
I have a ASP.NET page which has a form on it. It also has
I have an ASP.NET page which has a script manager on it. <form id=form1
I have form that displays several keywords (standard set of choice lists that changes
I have a form in C# that has a button that, when clicked, I
I have a login.jsp page which contains a login form. Once logged in the

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.