IE8 issue with javascript function that calls itself in setTimeout

I have a localization function defined in javascript

var locID;

function locateMe()
{
    if(locID > 0)
    {
        // i do a jquery post here
    }

    setTimeout(locateMe, 2000);
} 

// my document ready function is here, and inside it, at the end of it
// i do this
locID = 0;
locateMe();

when I check this code in firefox, the locateMe function is called every two seconds and works as expected. when I test the code in IE8, the function is never called (at least it is never called from what I see using the IE developer tools)

note: in the click event handler for code "zone_row", which modifies locID, code exists. again, in firefox, everything works as expected. strange in IE, when zone_row is clicked, the WILL function will be called ONCE. I see this both in the developer tools and as a result of the action of this jquery message.

, IE, . ?

EDIT: "locateMe();" setTimeout.

UPDATE: ( ), ( , ).

<script type="text/javascript">
    var z_items;
    var locID;

    function locateMe()
    {
            if(locID > 0)
            {
                    // my jquery post is here                   
            }   

            setTimeout(locateMe, 2000);
    }

    $(document).ready(function()
    {
            // ... some click events and get requests here ...

            locID = 0;
            locateMe();
    });
</script>

setTimeout ( ) DOCTYPE ( IE , , ONCE ).

+3
3

. , :

JQuery AJAX

$.ajaxSetup({cache: false}); , , . , .

+2

, IE ( IE9), self-called , . , Toddeman ajax.

, :

function locateMe()
{
    /* ... */   

    //IE way (still works in Chrome and FF):
    setTimeout(function () { locateMe(); }, 2000);

    //original: setTimeout(locateMe, 2000);
}
+1

Use

setTimeout( locateMe, 2000 );
0
source

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


All Articles