The ajax() is async function and the statements under it might execute before the ajax call is completed. You have to hide in success or done function.
$("#loading-popup").show();
$.ajax({
// ajax here
}).success(data){
$("#loading-popup").hide(0);
})