I have the following code to show a loading image whenever an AJAX request is being made.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<script>
$body = $("body");
$(document).ajaxStart(function(){
$body.addClass("loading");
}).ajaxStop(func(){
$body.removeClass("loading");
});
$.get(`example.com`,
func(html){
$("html").html(html);
alert("Load was performed.");
});
</script>
The code should show a gif whenever an AJAX request is made, and then hide the gif when all ajax requests complete so that only the new HTML document from the response is shown. However, the webpage stays blank, and the browser console shows the error:
Uncaught SyntaxError: missing ) after argument list
The CSS used here is from the answers to the question How can I create a "Please Wait, Loading..." animation using jQuery?