I am working on sharepoint server 2013. and i have a list named "links" of type prompted links. now i write the following jQuery code to query the links and show them inside a page:-
$(function () {
var htmlinit = "";
htmlinit = "<image id= 'customloader' src= '/resources/ajax-loader.gif'></image>";
$("#inserhere").after(htmlinit);
var html="<div ><div ><a href='/Lists/UsefulLinks/AllItems.aspx'> Links </a> </div><ul >";
$.ajax({
url: "/_api/web/lists/getbytitle('Useful Links')/items?$select=Title,LinkLocation&$orderby=TileOrder asc",
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++){
var nurl = items[i].LinkLocation.Url.toString();
var ntitle = items[i].Title.toString();
html+="<ul ><li ><a href=" + nurl + " target='_blank'>"+ ntitle + "</a></li></ul>";
}
html+="</ul></div>";
$("#inserhere").after(html);
$("#customloader").hide();
}
},
error: function (data) {
}
});
$("#customloader").hide();
});
this code should do the following:-
- show a loading image
- call the api rest endpoint of a list
- show the list items.
- hide the loading image.
now the above will show the items the way i want without any problem. but the only issue i am facing is that the
<image id= 'customloader' src= '/resources/ajax-loader.gif'></image>
is not being shown, even if the links takes around 10 seconds to load,, no loading image will be shown. now if i remove the $("#customloader").hide(); the loading image will be shown always (but of course this is not what i am looking for). so can anyone advice why i can not show the loading image till the rest api call construct the output ??