0

This is my code,

<script type="text/javascript">
var refreshId = setInterval(function () {
var pathtopage = window.location.href;
$('#refreshing').load(pathtopage + '#refreshing');
},2000);
</script>

When i run the code,i got error like this

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.

How to rectify the error

2
  • load() should be asynchronous anyway? Commented Feb 11, 2016 at 9:55
  • @BenM the default is set to async: true. I have noticed that it has to be explicitly specify. Commented Feb 11, 2016 at 10:11

1 Answer 1

2

Not sure what you are doing with window.location.href, but this how you should be doing, where you are calling an end point that returns you something ... his would do the job.

 $(function() {
        start();
    });

    function start() {
        setTimeout(start,2000);
        $.get(pathtopage, function(data) {
            $('#refreshing').html(data);    
        });
    }
Sign up to request clarification or add additional context in comments.

5 Comments

I need to refresh every 5 seconds.How can i use setTimeout
@Nisha.A Please read this for setTimeout explanation w3schools.com/jsref/met_win_settimeout.asp change 2000 to 5000
@Nisha.A search more .. this is offtopic how to set endless timeout.
@MarcosPérezGude there is a fundamental difference between interval and timeout. Then write setInterval in $(function() { setInterval(start, 5000) }); once and forget. Don't forget to clear Interval :))
@Nisha.A It should be just a warning, otherwise, set async to false and see the impact. You will have to replace $.get with $.ajax I think. You could try quickly by typing this command - $.ajaxSetup({async:true}) before you call start(); but it is not recommended as ajax will become sjax :))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.