Hello friends,
I have 2 tables that I populate with AJAX. I have now noticed that such a short interval between the calls, practically within a millisecond, occasionally leads to a problem with the
evaluation using .done and .fail.
Now I have changed the call to a callback-based solution.
Best regards,
Otto
I have 2 tables that I populate with AJAX. I have now noticed that such a short interval between the calls, practically within a millisecond, occasionally leads to a problem with the
evaluation using .done and .fail.
Now I have changed the call to a callback-based solution.
Best regards,
Otto
function myajaxRequest(params, callback) {
  $.ajax({
   url: "./data.prg",
   type: "POST",
   dataType: "json"
  })
   .done(function (data) {
    console.log(data);
    console.log("ajaxRequest .done");
    var message = data.array;
    params.success({
     total: data.total,
     rows: message
    });
    if (isFunctionExecuting) {
      console.log("isFunctionExecuting true");
     // Wenn isFunctionExecuting true ist, rufen wir die Funktion erneut mit dem Callback auf
     myajaxRequest(params, callback);
    } else {
     console.log("isFunctionExecuting else");
     // Wenn isFunctionExecuting false ist, rufen wir das übergebene Callback auf
     if (typeof callback === "function") {
      console.log("callback");
      callback();
     }
    }
   })
   .fail(function () {
    alert("Erfassungsjournal - Lesefehler");
   });
 }
 // Beispiel für die Verwendung der Funktion mit dem Callback
 var isFunctionExecuting = true; // Setze isFunctionExecuting auf true, um den asynchronen Prozess zu simulieren
 myajaxRequest({
  success: function (data) {
   console.log("Erfolgreich!");
   console.log(data);
   isFunctionExecuting = false; // Setze isFunctionExecuting auf false, um den Prozess abzuschließen
  }
 }, function () {
  // Callback-Funktion, die aufgerufen wird, sobald isFunctionExecuting auf false gesetzt ist
  console.log("Der asynchrone Prozess wurde abgeschlossen.");
 });