JQuery ajax call stops when loading prompt is displayed

In the code below, I use the jQuery ajax () function to call a long command. While the ajax function is running, I click on the link to download Firefox (for example), and the ajax call stops.

In fact, he acts as if the call was successful, but he was not, he just stopped.

Why? I want to continue working ...

I saw this problem in Firefox and Chrome. I have not tested other browsers.

    <!DOCTYPE html>
 <html lang="en">
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>

   <script type="text/javascript">

    function longPoller() {

        $.ajax({
            type: "GET",
            url: '/long-loading-page.php', /* <?php sleep(5000); ?> */
            dataType: 'json',
            async: true, 
            cache: false,
            timeout:50000, 

            success: function(data){ 

                alert('success');
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){

                alert('error');
            },

            complete: function() { 

                alert('complete');
                }

        });
    }


     $(document).ready(function(){
        setTimeout(function(){ longPoller() }, 1000); //start the longPoller() function
     });

   </script>
 </head>
 <body>

   <a href="http://download.mozilla.org/?product=firefox-3.6.9&os=win&lang=en-US">download Firefox! (clicking this link will stop the jQuery ajax call... why?)</a>
 </body>
 </html>
+2
source share
1 answer

, . , .. target="_blank" iframe .

+3

Source: https://habr.com/ru/post/1764064/


All Articles