Is it possible to use jQuery to insert a div into another div? My goal is to replace the contents of one div with a loading div while waiting for an ajax call to return.
<div id="content1">foo</div>
<div id="content2">bar</div>
<div id="loadingDiv" class="loading-indicator"></div>
I have a common ajax function that takes a div id and request url, and updates the div contents once the request is finished:
MyCommon.GetAjaxCall(fetchUrl, data)
.done(function (responseData) {
// On success, update content
$(responseContainer).html(responseData.View);
})
My intention is to display the loading animation in the div and then replace it with the response contents once the ajax call is complete. I've tried using
$(responseContainer).html($("#loadingDiv").show());
(and variations), as well as appendChild before the GetAjaxCall, but without success. I want each div on my dashboard-style layout to load data independently and still display the same loading animation. Am I approaching this problem correctly?