How to show loading spinner in jQuery?

There are a couple of ways. My preferred way is to attach a function to the ajaxStart/Stop events on the element itself. $(‘#loadingDiv’) .hide() // Hide it initially .ajaxStart(function() { $(this).show(); }) .ajaxStop(function() { $(this).hide(); }) ; The ajaxStart/Stop functions will fire whenever you do any Ajax calls. Update: As of jQuery 1.8, the documentation … Read more

Creating a new DOM element from an HTML string using built-in DOM methods or Prototype

Note: most current browsers support HTML <template> elements, which provide a more reliable way of turning creating elements from strings. See Mark Amery’s answer below for details. For older browsers, and node/jsdom: (which doesn’t yet support <template> elements at the time of writing), use the following method. It’s the same thing the libraries use to … Read more

How to return AJAX response Text? [duplicate]

remember that onComplete is called long after the someFunction is done working. What you need to do is pass a callback function to the somefunction as a parameter. This function will be called when the process is done working (ie, onComplete): somefunction: function(callback){ var result = “”; myAjax = new Ajax.Request(postUrl, { method: ‘post’, postBody: … Read more