I have a script which dynamically loads data onto a restaurant menu for printing. Could the following code could be shortened at all?
<script>
$(document).ready(function(){
$('#prestarters').load('prestarters.php', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".s").html(msg + xhr.status + " " + xhr.statusText);
}
});
$('#starters').load('starters.php', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".s").html(msg + xhr.status + " " + xhr.statusText);
}
});
$('#mains').load('mains.php', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".s").html(msg + xhr.status + " " + xhr.statusText);
}
});
$('#sides').load('sides.php', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".s").html(msg + xhr.status + " " + xhr.statusText);
}
});
$('#dessert').load('dessert.php', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".s").html(msg + xhr.status + " " + xhr.statusText);
}
});
$('#dessertwines').load('dessertwines.php', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".s").html(msg + xhr.status + " " + xhr.statusText);
}
});
$('#afterdinnerdrinks').load('afterdinnerdrinks.php', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".s").html(msg + xhr.status + " " + xhr.statusText);
}
});
$('#whiskeys').load('whiskeys.php', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".s").html(msg + xhr.status + " " + xhr.statusText);
}
});
$('#hotdrinks').load('hotdrinks.php', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".s").html(msg + xhr.status + " " + xhr.statusText);
}
});
$('#ports').load('ports.php', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".s").html(msg + xhr.status + " " + xhr.statusText);
}
});
$('#cognacs').load('cognacs.php', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".s").html(msg + xhr.status + " " + xhr.statusText);
}
});
$('#liqueurs').load('liqueurs.php', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".s").html(msg + xhr.status + " " + xhr.statusText);
}
});
});
</script>
Also, is there a way to alert the user once all data has been loaded? I currently have a message which tells the user to wait 5 - 10 seconds before printing...