I have two ajax requests to check if two images are available. The ajax calls are as follows:
if (result['img_one'] !== '') {
var src_one = "blah-blah-one.jpg";
$.ajax({url: src_one,
success: function(data, textStatus) {
$("#profile-box").show();
$("#profile-img").attr("src", src_one);
},
error: function(jqXHR, textStatus, errorThrown) {
$('#profile-box').hide();
}
});
}
if (result['img_two'] !== '') {
var src_two = "blah-blah-two.jpg";
$.ajax({url: src_two,
success: function(data, textStatus) {
$("#profile-box").show();
$("#profile-pic").attr("src", src_two);
},
error: function(jqXHR, textStatus, errorThrown) {
$('#profile-box').hide();
}
});
}
Now, I want to check if both the above requests succeed or not. If both of the requests return successfully and hence both images are available, I want to hide a div in my page.
How can I check that? I tried to set two variables when the requests succeeded, to check their values through an if-block and hide the div. however, they were not accessible outside the if-block. Any help will be much appreciated.