1

After a lot of digging i came up with using $.get() method and implemented it as follow -

var id = setInterval(frame, 1000);
    function frame() 
        {
            if (progressBar.dataset.size == 100) 
            {
                clearInterval(id);
            }
            else {
                $.get('Progress1.txt', function (data1) {
                    progressBar.dataset.size = data1;
                    foreground.style.width = data1 + '%';
                    foreground.className += ' ' + newClass;
                    progressPercent.innerHTML = data1 + '%';

                });
            }

        }

e.g if the text file content is 40 then i have to set the width of my progress bar as 40%. The value of text file keeps changing dynamically in my backend(C#). so i have to keep checking it until the content of text file reaches 100 in frontend(jQuery/JavaScript). Now, the page runs fine for the first time. But when i try to change the content of text file manually it is not reflected in my progress bar. Moreover after running it again for second time i get the same content that i used first time in my text file.

sourav
  • 13
  • 5
  • So you've ended up with a solution or still asking for something? I could not figure it out, sorry. – vahdet Feb 06 '18 at 07:16
  • My progress bar do not change dynamically as i change the content of my text file. It just uses the first content as value that i used while creating the text file.So this is the problem. – sourav Feb 06 '18 at 07:27
  • May be this will help [https://stackoverflow.com/questions/14446447/how-to-read-a-local-text-file](https://stackoverflow.com/questions/14446447/how-to-read-a-local-text-file) – kgzdev Feb 06 '18 at 09:02

1 Answers1

0

Thanks for the above suggestions. But i figured out that I have to abort the file after the end of loop using-

 $.get('Progress1.txt').abort();

So that everytime the loop starts it loads the server file again rather than using the old copy which was in the case when we did not used abort().

sourav
  • 13
  • 5