I am working on an asp.net web application, and inside it i am trying to do the following :-
- call 2 rest API
- show an ajax loading image
- build a list of the result
- hide the loading image
here is my code:-
<script type="text/javascript">
var htmlinit = "";
htmlinit = "<image id= 'customloader' src= '/resources/ajax-loader.gif'></image>";
$(".ms-core-listMenu-root>li:contains('Projects')").before(htmlinit);
$(function () {
function getAssetsListItems(){
var results="";
var url = "/_api/web/lists/getbytitle('Projects')/items?$filter=SiteAutomaticallyCreated eq 'Yes'&$select=ID,Title,ProgrammeRevissionId&$orderby= Title asc";
$.ajax({
url: url,
method: "GET",
async: false,
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
if(data.d.results.length>0){
results = data.d.results;
}
},
error: function (data) {
}
});
return results;
}
var assets=getAssetsListItems();
var url = "/_api/web/lists/getbytitle('Programme or Version Release')/items?$select=ID,Title&$orderby= Title asc";
var html="";
$.ajax({
url: url,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
if(data.d.results.length>0){
var items=data.d.results;
for(var i=0;i<items.length;i++){
html+="<li class='static'>"
+"<span tabindex='0' class='static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode'>"
+"<span class='additional-background ms-navedit-flyoutArrow'><span class='menu-item-text' style='color:#00AEEF;font-weight:bold'>"
+items[i].Title+"</span></span></span>";
html+="<ul class='static'>";
for(var j=0;j<assets.length;j++){
if(assets[j].ProgrammeRevissionId==items[i].ID){
var idd = assets[j].ID.toString();
var ntitle = assets[j].Title;
html+="<li class='static'>"
+"<a tabindex='0' class='static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode'"
+"href=/businessfunctions/PMO/Projects/"+idd+">";
}
}
html+="</ul></li>";
}
$(".ms-core-listMenu-root>li:contains('Projects')").after(html);
$("#customloader").hide();
}
},
error: function (data) {
}
});
});
</script>
the problem i am facing is that the loading image will not be hidden. so this line of code:-
$("#customloader").hide();
is not working as expected, although i will get my HTML result created correctly. so currently the loading image will be shown, then the result will be rendered, but the loading image will stay loading on the screen...
Thanks