When making recursive AJAX calls, the script that is included between each recursion is not being executed

My recursive Ajax call is functioning correctly (the PHP script is doing its job, recursion is working, everything is fine) EXCEPT that in between the ajax calls, I am trying to update an input text value to show the progress, but it only updates once the entire loop is done.

I'm wondering why this line of code isn't executing:

$('#start_'+code_regional).val(msg);

Any insights on why this might be happening?

function addLeads(code_regional, phone_numbers_start)
    {
        var databases = [];
        var file = document.getElementById('file_'+code_regional).files[0];

        var formData = new FormData();
        formData.append('selectedDatabases', JSON.stringify(databases));
        formData.append('code_regional', code_regional);
        formData.append('phone_numbers_start', phone_numbers_start);
        formData.append('phone_numbers_end', $('#end_'+code_regional).val());
        formData.append('filePath', file);

        $.ajax({
           type: 'POST',
           url: 'execute.php',
           data: formData,
           processData: false,
           contentType: false,
           success: function(msg){
                $('#start_'+code_regional).val(msg);
                if(msg < $('#end_'+code_regional).val())
                {
                    addLeads(code_regional, msg);
                }
                else
                {
                    $('#start_'+code_regional).val($('#end_'+code_regional).val());
                }
           }
        });
    }

Answer №1

Ensure to compare integers instead of strings when msg is an integer:

If( parseInt(msg,10) < parseInt($('#end_'+area_code).val(),10) )

If the issue persists, consider inserting a console.log(...) before and after the assessment for better understanding.

Answer №2

Could you clarify what is meant by between the ajax calls? The script seems to indicate that if the message count is below a certain threshold, then it will call the addLeads function again; otherwise, it will update the starting field. This doesn't really track progress as the start field is only updated at the end. If constant updating is desired, consider moving the update line outside of the conditional statement.

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

Having issues with using setTimeOut within a for loop in JavaScript React

I'm currently working on a visual sorting algorithm application using React. My implementation involves bubble sort, where I generate an array of numbers from 1 to 50, shuffle them, and then apply the bubble sort method to sort them. However, I am fac ...

Issue with TypeORM @BeforeInsert causing a field in Entity not to be populated with value

Currently, I am facing an issue where I am attempting to update or insert into a token field before the record is saved. However, when utilizing the @BeforeInsert hook, I encounter the following error: "error": "Cannot read property 'co ...

JavaScript issues in FireFox and Internet Explorer when using JQuery

I have developed a PHP GD image for generating captcha images, saved as image.php. Each time it creates a unique captcha image. Inside the signup.php file: <img alt="" src="image.php"> <input type="button" id="btn" value="cannot read captcha"&g ...

Express: when req.body is devoid of any data

My server code using Express: const express = require('express'); const exphbs = require('express-handlebars'); const path = require('path'); const bodyparser = require('body-parser'); const app = express(); cons ...

Summoning within a rigorous mode

I am facing an issue with my configuration object: jwtOptionsProvider.config({ tokenGetter: (store) => { return store.get('token'); }, whiteListedDomains: ['localhost'] }); In strict mode, I ...

How can one generate an HTML element using a DOM "element"?

When extracting an element from an HTML page, one can utilize a DOM method like .getElementById(). This method provides a JavaScript object containing a comprehensive list of the element's properties. An example of this can be seen on a MDN documentat ...

An unusual error occurred stating that the `forEach` property does not exist on the given type

I am working on a chess game and encountering some Typescript errors that I'm struggling to comprehend. The issue arises in the following class method: clickEvent (e: MouseEvent): void { const coordinates: ClientRect = this.chessBoard.getBounding ...

Using AJAX to retrieve Django view return values

I am currently using Django along with AJAX, Within my template, users have the ability to select an option and then submit their choice. Upon clicking the submit button, an Ajax function is triggered which sends the data to my view for processing, and th ...

Tips for designing a personalized payment page in PayPal for flexible one-time and subscription-based payments

How can I display a PayPal checkout page with custom fields such as tax and total amount when a user makes a payment for a custom amount? Can multiple fields like sales tax and total amount be added? In addition to that, our web application already has Pa ...

Utilize AJAX and C# to seamlessly map JSON data onto an object

What is the best way to utilize JSON formatted data received from an AJAX request in C#? Check out this View with JQuery and AJAX: <script type="text/javascript"> $(function () { $("#btnGet").click(function () { var values = ...

I am having trouble retrieving the properties of "2d" objects using tiles[i-1], unlike standard objects in JavaScript

I've been working on constructing a random map generator by utilizing a grid composed of tiles within a canvas. In my process, I'm investigating the properties of each tile tiles[i] before handling tiles[i-1]. While this procedure seems to functi ...

Are there any methods to determine the way in which a user has absorbed the content of a post

This particular question sets itself apart from the one found here, as it aims to detect various user behaviors beyond just browser activity. Specifically, I am interested in identifying behaviors such as: Rapidly skimming through an article from start ...

Initiating a Page with Dynamic Modal Window according to Backend Exigencies

Dear experts, can you help me with a problem? I want to implement a modal window on an vb.aspx page if a specific condition from the codebehind query is true. How can I achieve this? Thank you! ...

Requesting a resource using the HTTP GET method returned no data

Looking to process the response from an http-request using JavaScript? Check out this straightforward example below. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html x ...

AngularJS - Unusual outcomes observed while utilizing $watch on a variable from an external AngularJS service

Within the constructor of my controllers, I execute the following function: constructor(private $scope, private $log : ng.ILogService, private lobbyStorage, private socketService) { this.init(); } private init(){ this.lobbyData = []; this.initial ...

Error encountered while attempting to save a Mongoose post on Heroku, although it is successful

My aim is to post to my MongoDB Atlas database using node, express, mongoose, and Heroku. While a Postman POST request with Raw JSON body: { "title": "heroku post", "description": "post me plsssss" } works f ...

Verify the Existence of Date and Time Range in SQL SERVER

I am dealing with the following set of data ID empID FromDate ToDate FromTime ToTime 1 00001 09/11/2018 09/11/2018 10:00 AM 11:00 AM 2 00001 09/11/2018 09/11/2018 08:00 AM 09:00 AM 3 00001 09/11/2018 09/11/ ...

Tips for keeping a floating action button visible at the bottom of the screen at all times

I am currently utilizing the Material UI framework. I have a floating action button that I would like to display in a specific position on the page without it moving when scrolling, and I am also wondering if this is a common issue. Below is the code sn ...

Determine the width of invisible images using JavaScript/jQuery

Please take a look at the jsFiddle Every time I run it, I am trying to retrieve the width of the images, but the values I get are as follows (check in the JS console) 400 0 575 533 0 ... Some values are zero, and I can't figure out why. It seem ...

Update the records and refresh the dropdown menu with the new array using AJAX

Current Situation: Using Laravel 4.2, I have a form that includes a select box. {{ Form::select('NameCustomary', $ent) }} The select box is pre-populated with persons' names. In the controller: $ent = array('' => 'Choose ...