Develop a dynamic progress bar with Symfony 2 Framework to display status updates as a task is being executed

Having conducted extensive research and testing, I find myself in a situation where posting this information request is my last resort. Despite numerous attempts, I have been unable to achieve the desired outcome.

My goal with Symfony Framework v2.8 is rather straightforward - I want to animate a bootstrap progress bar while executing an action in a controller when a user clicks on a button.

The approach I am taking involves:

  • Updating a SESSION variable during the processing of an action
  • Reading this SESSION variable in another action

When a user triggers the button click:

  • I use AJAX to execute the processing action
  • I use AJAX again to read the SESSION variable until the processing action is completed

In essence, it's a simple process. However, the challenge I'm facing is that the reading action for my SESSION variable does not occur simultaneously during the processing action.

I can perform the treatment before and after, but not during the execution phase.

This inability to read the SESSION variable in real-time hinders my ability to animate the progress bar effectively.

Below is the JavaScript code snippet:

$('#generator').click(function() {

    var isInProgress = false;

    traitement();

    function traitement()
    {
        isInProgress = true;
        checkProgress();
        $.ajax({
                type: "GET",
                url: '{{ path('sws_back_createplanning', { 'idChampionnat': Championnat.id })}}',
                async : true,
                cache: false,
                dataType:'html',
                success: function(data){},
                error: function(){  },
                complete: function(){
                    isInProgress = false;
                }
        });
            
    }  

    function checkProgress()
    {
        if( isInProgress != false )
        {
            $.ajax({
                type: "GET",
                url: 'championnat/getprogress/',
                async : true,
                cache: false,
                dataType:'html',
                success: function(data){

                     /* animation de la progress bar */

                 },
                error: function(){  },
                complete: function(){
                    checkProgress();
                }
            });
        } else { }
    }
})

Here is the processing action code:

public function traitementAction($id){


$session = new Session();
$session->set('progress', 0);

// traitement #1

$session->set('progress', 25);

// traitement #2
......and so forth.....

The issue pertains to the inconsistency in executing both queries concurrently. It seems like there might be a missed step or misunderstanding on my end. Any assistance would be greatly appreciated.

Sincerely,

Answer №1

Issue resolved ... it turned out to be related to session management (closing session).

Check out this link for more information:

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

The Ajax Form disappears from the page

After racking my brain for a while, I've come to the conclusion that it's time to seek some assistance. I have work tomorrow and I don't want to spend all night on this. The issue lies in my form which is located inside a modal, here is my ...

The FieldError in Django is throwing an error because it cannot recognize the keyword 'productcategory_id' as a valid field. The available choices for fields are country, country_id, id, name, and vendor

I'm currently facing an issue while using Django dependent dropdown lists. When attempting to make an Ajax request by clicking on the product category, I encounter an error. The dependent dropdown does not work simultaneously with making an Ajax reque ...

"Encountering issue with $.ajax() not accepting PHP array as

I am currently utilizing ajax to fetch data from a table stored in a MySQL database. The ajax calls are being made using jQuery, with the databases being accessed through PDOs. PHP function fetchQuestions() { $database = "answerMe"; // n ...

Accessing WebService Remotely Using Ajax in ASP.NET

CLIENT - AJAX $.ajax({ type: "POST", url: 'http://www.website.com/Service.asmx/Method', data: "{ 'username': 'testuser', 'password': '123456' }", contentType: "applicati ...

Simultaneous malfunction of two ajax forms

I have a dilemma with two boxes: one is called "min amount" and the other is called "max amount." Currently, if I input 100 in the max amount box, it will display products that are priced at less than $100. However, when I input an amount like $50 in the m ...

The content within the tab is currently being loaded

Incorporating jQuery UI tabs into my webpage, I encounter a delay of 5-6 seconds when clicking on a tab as it triggers an ajax call for preparing and displaying content. The screen stays idle during this time, leading to user confusion. I am seeking a sol ...

JavaScript struggles when dealing with dynamically loaded tables

I am currently working on integrating the javascript widget from addtocalendar.com into my website. The code example provided by them is displayed below. Everything functions as expected when I place it on a regular page. However, I am facing an issue wher ...

"Exploring the power of Ajax: a guide to automatically refreshing the response every

I am struggling to understand why this snippet of code isn't working as expected. The div updates when using .html, but not with my custom script. In my setup, I have two files: index.php and test.php The index file looks like this: $(document).rea ...

Harness the power of Highcharts through an Ajax request to retrieve a JSON file

I am having an issue using Highcharts with a JSON file from an external server. When I try to bind the returning file to the chart in my ASP.NET MVC application, it doesn't work. Here is the code I have attempted: http://jsfiddle.net/Q6ngj/2/ jQuery ...

Ideas for displaying data or a message only once when selecting multiple checkboxes in jquery

code: <script> $(document).ready(function(){ $(".choose").click(function(){ job_type = $(':checked').map(function() { return this.value; }).get().join(',&ap ...

Tutorial: Using Laravel 5.6 to transfer selected value from Dropdown menu to PHP variable using Ajax on a single page

In my current project, I am utilizing Laravel 5.6 alongside PHP 7.1.9. On a specific page (pages/cardview.blade.php), I have a dropdown box with different options and PHP conditions to check the selected value from this dropdown. Based on the selection, ce ...

"Enhancing Shopify experience by seamlessly adding products without the need for page refresh

Welcome to my first post on this platform. I recently implemented a list of products in my Shopify mini cart, and although the products are successfully added to the cart, clicking "add to cart" redirects me to the cart page. Is there a way to add products ...

Unlock the secrets of creating an interactive chat room effortlessly by harnessing the power of J

In search of implementing a unique chat room using PHP and JavaScript (Jquery) offering group chat as well as private chat functionalities. The challenge lies in finding a way to continuously update the interface seamlessly, while also displaying 'X ...

The Calendar Extender does not appear when used with masterpages

I'm having trouble with my masterpages as I can't seem to get my calendarextender to display after going through numerous solutions. Take a look at my code below: http://pastebin.com/m789f935e ...

The SELECT statement fails to fetch the most recent data from the database following an INSERT operation

When I make an AJAX request to the same page, my success function in PHP inserts a new record into a table called "some_table" in a MySQL database. Following that, I use jQuery to select data from this table and display it on the page. However, all old rec ...

Sending values to the onSuccess callback function

I am working with the following form: @using (Ajax.BeginForm("DoComment", "Publication", new { id = Model.Publication.OID, parentId = Model.OID }, new AjaxOptions { OnSuccess = "publishCommentSuccess" })) { ...

What could be causing the issue where only the latest data is being shown

When I use ajax to retrieve data from my database, the console.log displays all the results correctly, but in my HTML, only the last result is shown. What could be causing this issue? Any help would be appreciated! Thanks! Please keep your response simple ...

Display a variety of images upon submitting an AJAX request

When I make an AJAX request to display an image: $('div.loading').ajaxStart(function(){ $(this).removeClass('none'); }).ajaxComplete(function(){ $(this).addClass('none'); }); But I nee ...

jQuery Form: Despite the Ajax response being visible on the page, it does not appear in the source code

Utilizing Jquery Form for an Ajax image upload. This is the relevant HTML code: <div class="input_con imageupload_con"> <form action="processupload.php" method="post" enctype="multipart/form-data" id="MyUploadForm"> < ...

Getting the output from AJAX when the onreadystatechange event occurs

Struggling with retrieving a value from a function and storing it in a variable? Getting an "undefined" result due to JavaScript's asynchronous nature? Unsure how to fix this using "callbacks" or "promises"? Check out the code snippet below. The goal ...