Ensure that JavaScript functions are executed sequentially without overlapping

Important : Absolutely no jQuery allowed

I have developed four distinct functions and I am looking to execute them sequentially, one after the other in JavaScript without using jQuery. I have scoured the internet for a solution but unfortunately have not found a satisfactory answer. Here is an overview of what I have accomplished so far:

function func1() {
    noAjaxCall.click();
    return true;
}

function func2() {
    ajaxCall.click();           <--------- making an AJAX request
    return true;
}

function func3() {
    noAjaxCall.click();
    return true;
}

function func4() {
    //any code can be inserted here
}

if(func1())
    if(func2())
        if(func3())
            func4();

The issue that I am facing is that func3 does not get called. Can someone help me understand why this occurs and suggest a potential workaround?

Thank you!

Answer №1

It seems like your expectations are not aligning with reality. When func3 is called, the AjaxCall may not be completely finished because it's asynchronous.

I recommend focusing on finding the actual solution to your problem rather than just trying to patch it up temporarily.

Can you provide more insight into the ultimate goal you are aiming to achieve?

edit

Consider handling the 'click' event for ajaxCall. I understand that jQuery may not be available in your application, but here's an example based on my knowledge:

function requester(){
    //do some asynchronous work
    $.ajax({ //...
        success: function() {
            //Invoke other functions here
        }
    });
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to detect hover (etc) events after generating div elements with innerHTML method

After using the code below to generate some divs document.getElementById('container').innerHTML += '<div class="colorBox" id="box'+i+'"></div>'; I am encountering an issue with capturing hover events: $(".colorB ...

How can I prevent an HTML element from losing focus?

Currently, I am developing an online editor that requires accurate character inputs. To achieve this, I have implemented the jQuery.onKeyPress event on a textarea element. This approach was chosen because obtaining character inputs from the body directly p ...

Error 504: The gateway is taking too long to respond because of an

When using jQuery.ajax, I encountered the following error: 504 - Gateway Time-out Error request = $.ajax({ url: Raiz + "/informes/Inventario/pdfInventarioAlmacenValorado.php", type: "POST", data: data, timeout: (600 * 1000), su ...

Making an AJAX request to a remote site through CORS while the rest of the page is utilizing the file:// protocol

When the page loads, it is loaded with: file:///opt/x/index.html. The index.html file contains AngularJS and UI-Bootstrap JavaScript and CSS files. It also has a variety of divs with Bootstrap columns and rows. The contents of index.html are as follows: ...

Cut off all information beyond null characters (0x00) in Internet Explorer AJAX responses

When using Internet Explorer (IE6, IE7, and IE8), null characters ("0x00") and any subsequent characters get removed from ajax responses. Here's the code snippet that showcases a loop of AJAX requests: var pages = 10; var nextnoteid = 0; for (isub ...

Tips for passing an array from AJAX to Controller in asp.net:

I'm currently working on sending an array from an AJAX POST request to my controller. Here's what I have: var selected = []; $('.unitsCheckBox:checked').each(function () { selected.push($(this).val()); }); data = { Units: sele ...

Managing the rendering of charts in Angular with Directives

I'm in the process of creating an admin page with multiple elements, each revealing more information when clicked - specifically, a high chart graph. However, I've encountered a challenge with the rendering of these charts using a directive. Curr ...

Is it possible to update table cell content depending on selected option?

Displayed here is the select block: <form> <select id="select"> <option disabled selected value="choose"> CHOOSE </option> <option value="i2g" id="i ...

Alter the Color of the 'div' According to the Background

At the bottom right of my website, there is a black chatbot icon. The web footer also has a black background. To create a clear contrast, I have decided to change the color of the chatbot to white as users scroll to the bottom of the page. I implemented t ...

"Use jQuery to target the first child element within a parent element that has a specific class

Is there a way to choose only the first child of a specific parent class with a certain class for the purpose of clone()? <div class="sector_order"> <div class="line_item_wrapper"> SELECT THIS DIV </div> <div class=" ...

What is the best way to achieve a smooth rotation effect ranging from 1° to 359° using HTML/CSS in conjunction with JavaScript

Currently, I am retrieving rotation data from a sensor and transmitting it to a webpage containing a 2D-Model that rotates based on this data. To ensure a smoother motion, I have incorporated a CSS transition. However, an issue arises when the rotation da ...

Encountered an Xpath error while attempting to create a random email generator using Selenium IDE

While attempting to execute a script, I encountered an "element not found" error with Selenium failing to detect the xpath. My goal is to randomly generate email addresses. Every time there is an error message stating: [error] Element .//[@id='GmailA ...

The ng-view DIV in Angular JS 1.x mysteriously vanishes

Currently, I am working on a project that involves angularJS and ASP.NET in Visual Studio 2013. However, I have encountered a frustrating issue where my DIV node for ng-view is being replaced with an ng-view comment without any errors appearing while testi ...

load google map with geocoding on an ajax-enabled page

I'm currently working on a webapp where I use AJAX to load all the pages. Recently, I faced a challenge of loading a Google map along with a page and here's how I tackled it: Great news! I managed to successfully load a Google map using just an ...

Tips for customizing the WooCommerce product page

If you want to customize the layout of a WooCommerce product page, you can override the template by copying the WooCommerce template folder into your theme. You can find step-by-step instructions here. I am looking to change the layout of a WooCommerce pr ...

Learn how to transform a raw readme file into an HTML formatted document using AngularJS, after retrieving it from GitHub

Can someone help me figure out how to format each line of the README.MD raw file into an HTML document using the controller below? angular.module('ExampleApp', []) .controller('ExampleController', function($scope, Slim,$sce) { ...

Tips for adding animation to a React state value change triggered by an input

In my React application, I have a form with multiple fields that each contain a text input and a range input. Currently, both inputs share the same state value and onChange function to keep them synchronized. However, I would like to add an animation effe ...

Is onMouseLeave failing to trigger upon exiting an element?

Having an issue with the onMouseLeave event in React. It seems to be triggering when hovering over other elements like the navbar or console, but not when leaving the intended element. function GameCard({name, about, image}) { const [active, ...

Can you please explain the distinctions between these terms as they relate to web applications?

Could you please provide a comprehensive explanation of the distinctions between these various terminologies? 1-Post back 2-auto post back 3- submit 4- refresh(F5) 5- request the same URL 6- AJAX call I appreciate your assistance. ...

How can I remove the script from Response.Write?

Instead of using Response.Write to test some values in code with an alert box, I tried writing dynamic javascript directly into the page. Even after reverting the code, rebuilding, and clearing all temp data from IE, the alert still pops up. I followed a ...