javascript clearInterval not clearing the interval, can someone please help me? [closed]

i used setInterval often but somehow I don’t understand it right now…

I decared the id var global, start the interval which works as expected, the clearInterval section is called but the interval continues running, even with some test code

var iv_st;

tried too:
var iv_st=false;

somewhere in php code:

                ?>
                <script type="text/javascript">
                <!--
                    iv_st=setInterval(getState, 2000, 'state');
                //-->
                </script>
                <?php

Interval is set:

later in javascript code (with some test code)

`function getState(id){
        console.log(iv_st);

        $('#'+id).html('getState called: waiting');
        $.ajax({
            url: "/lib/thumb_state.php?m=0",
            success: function(data){
                if (data!=''){
                    gScnt=0;
                    var ok=data.substr(0,1);
                    var d=data.substr(1);
                    if (ok==0){
                        $('#'+id).html(d);
                    } else if (ok==9){
                        clearInterval(iv_st); 
//                      iv_st=false;
                        $('#'+id).html(d);
                    } else {
                        $('#'+id).html(data);
                    }
                } else {
                    if (gScnt>5){
                        $('#'+id).html('getState aborted: '+gScnt+'x empty data');
                        clearInterval(iv_st); 
//                      iv_st=false;
                        gScnt=0;
                    } else {
                        gScnt++;
                        $('#'+id).html('getState running: empty data');
                    }
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) { 
                alert("getState Status: " + textStatus + ". Message: " + errorThrown); 
            }
        });  
    }`

getState is called as expected. clearInterval is called in the “normal” part of the function and in the test (if (gScnt>5)), but the interval is not cleared, continues to run, and the console continues to display the ID

can anyone tell me what I’m doing wrong or at least have an idea? otherwise I’ll just switch to setTimeout, but it bugs me not to understand the problem…