0

i checked everything but cant find the issue to change the gobal varibale duration, here is my code:

<script type="text/javascript">

$('#clock').countdown({ layout: '{mnn} : {snn}', timeSeparator: ':', until: 5, onExpiry: restartCountdown });

function restartCountdown() {

        var duration = 10;
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            duration = this.responseText;
            alert (duration);
            }
        };
        xmlhttp.open("GET", "waitingtime.php?date_entry=$date_entry,roomname=$rname2,uid=$uid", true);
        xmlhttp.send();

        $('#clock').countdown('option', {until: duration, onExpiry: reloadpage} );
    }

    function reloadpage() {
        location.reload();
    }

</script>
user2083524
  • 121
  • 1
  • 5
  • 16
  • Search for “javascript asynchronous return value”. This issue is quite common: the variable is accessed _before_ the variable has been assigned as result of the asynchronous call. – user2864740 May 02 '20 at 03:24
  • See, eg. https://stackoverflow.com/q/14220321/2864740 for details. – user2864740 May 02 '20 at 03:26
  • thanx it works now, xmlhttp.open with false, but i get this message: test3.php:86 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. – user2083524 May 02 '20 at 03:37
  • From comment in deleted answer: It generates a warning because forcing a synchronous request should not (or at least almost never) be used - and it should definitely not be standard choice. Follow the link in question comments above, as well as search suggestion. Alter to specific raw-XHR focus as desired. – user2864740 May 02 '20 at 03:38

0 Answers0