Replacement to jQuery ajax with async = false

Hello everyone,
Long time no see :slight_smile:
I’ve been recently working on a new site:

And i’ve got a few questions, so this topic will represent the first one :slight_smile:
When I open developer tools I see I have this warning coming from jQuery:

[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/.

I’ve already tried a few different solutions I found online, like:

  • Trying to do async:true and putting the code I need inside a success block.
  • Trying to use jQuery .get function and then putting the code I needed inside the .done function.

Both these methods removed the warning and caused no other errors, but the countdown timer stopped working.

Here’s a snippet of one of the things I tried:

$(document).ready(function() {
	$.get('/timer.php', function(time) {
		if (time < new Date().getTime()) {
			$('#clock-text').html('Season started since:');
			$('#clock').countdown({timestamp: time});
		} else {
			$('#clock').countdown({timestamp: time, callback: function(left) {
				if (left == 0)
					$('#clock-text').html('Season started since:');
			}});
		}
	});
});

I tried to print out the variable ‘time’ and it is correct, so I have no idea why the countdown isn’t showing up.
Any hints?
Thanks :slight_smile:

Managed to solve it, I forgot to create a new Date object from the time that is returned from the get function >_<
Something like:

$.get('/timer.php', function(time) {
	time = new Date(time).getTime();
	...
});

Amazing how one can find such things only after posting a question about it :smiley: sorry about that.

2 Likes

Happens to me all the freakin’ time, and I hate it. But, what can you do? Seems like I’ll Google for hours about something I’m having trouble with, can’t find anything, post to a forum.

15 seconds later, get an idea, Google the same thing but worded slightly different, find solution.

Facepalm.

Delete post, or post explanation that you found a solution.

  • headdesk * * headdesk * * headdesk * * headdesk *

V/r,

^ _ ^

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.