Test the existence of a file dynamically in javascript

2

I have a web page that launches a background script. Meanwhile there is a page that is shown with certain information. And I want that when the script has finished it shows me another information on that page.

When I launch the script I create a file test_still_running.txt and when I finish the execution of the script I delete it. The idea is to see dynamically with ajax if the file exists and when it ceases to exist detect it to show the information.

I tried the following, I just do not get the url of my file, so it does not work. I tried this, any ideas?

var url = "<?php echo json_encode(url(base_path() . "/public/test_still_running.txt")); ?>";
$.get(url)
        .done(function () {
            // exists code 
        }).fail(function () {
    document.getElementById("button").style.display = "block";
    document.getElementById("ok_alert").style.display = "block";
    document.getElementById("loading").style.display = "none";
});
    
asked by Sara Fernández Calleja 03.09.2018 в 11:09
source

0 answers