Question
for some reason, the todays's menu button is not working when the ajax and json are called via server. The other two buttons work: saturdays
for some reason, the todays's menu button is not working when the ajax and json are called via server.
The other two buttons work: saturdays and sundays.
Menu1.json
{
"House Daily Soup" :
{
"Description":"House made served with artisan bread and farm butter mostly (V) please ask",
"Price":"4.95"
},
"ANDY HOLTS SATURDAY BLACK PUDDING" :
{
"Description":"Bacon jam and soft poached egg",
"Price":"5.75"
},
"SATURDAY GRAVLAX" :
{
"Description":"Cured with beetroot and sea salt caper & lemon dressing",
"Price":"7.95"
},
"TEMPURA KING PRAWNS" :
{
"Description":"Toasted corn chilli puree",
"Price":"7.95"
},
"RARE BREED BABY BACK RIBS" :
{
"Description":"Basted in black treacle cola & chilli",
"Price":"6.50"
}
}
Menu2.json
{
"Lamb duo" :
{
"Description":"Pan-fried lamb rump and a Cheddar topped shepherds pie with seasonal vegetables and a red wine jus" ,
"Price":"4.95"
},
"Steak and mushroom pie " :
{
"Description":"Slow cooked beef with a red wine sauce, topped with puff pastry, served with mash, seasonal vegetables and a jug of gravy",
"Price":"5.75"
},
"Roasted vegetable tart" :
{
"Description":"Kale and thyme pastry filled with butternut squash, plum tomatoes, red onion, spinach and red peppers, with a leek sauce",
"Price":"7.95"
},
"Chicken and thyme pie" :
{
"Description":"In a creamy chenin blanc sauce, topped with puff pastry, served with spring onion mash and seasonal vegetables",
"Price":"7.95"
},
"Yorkshire ham and free range eggs" :
{
"Description":"with triple-cooked chips",
"Price":"6.50"
}
}
Menu3.json
{
"Fish and chips" :
{
"Description":"beer-battered, line-caught cod with triple-cooked chips, mushy peas and tartare sauce",
"Price":"4.95"
},
"Seared fillet of sea bass " :
{
"Description":"with crushed baby potatoes, asparagus and a lobster and samphire sauce",
"Price":"5.75"
},
"Pizza:Meat Feast" :
{
"Description":"Chicken, pork and fennel sausage, crispy bacon, mozzarella and a red onion chutney",
"Price":"7.95"
},
"Pizza- roasted vegetable" :
{
"Description":"red pepper, butternut squash, red onion, spinach and mozzarella(V)",
"Price":"7.95"
},
"Spicy diablo" :
{
"Description":"Pepperoni, chorizo, guindilla chill peppers, ozarella and a chipotle chilli jam",
"Price":"6.50"
}
}
menuButton.html
Click the button to get menu.
document.getElementById("button_today").addEventListener("click", clickToday, false);
document.getElementById("button_saturday").addEventListener("click", clickSaturday, false);
document.getElementById("button_sunday").addEventListener("click", clickSunday, false);
function clickToday()
{
var request = new XMLHttpRequest();
request.open('GET', 'Menu1.json');
request.onreadystatechange = function() {
if ((request.readyState===4) && (request.status===200)) {
var menus = JSON.parse(request.responseText);
var output = " ";
for (var key in menus) {
output += "
}
var update = document.getElementById('menu');
update.innerHTML = output;
}
}
request.send();
}
function clickSaturday()
{
var request = new XMLHttpRequest();
request.open('GET', 'Menu2.json');
request.onreadystatechange = function() {
if ((request.readyState===4) && (request.status===200)) {
var menus = JSON.parse(request.responseText);
var output = " ";
for (var key in menus) {
output += "
}
var update = document.getElementById('menu');
update.innerHTML = output;
}
}
request.send();
}
function clickSunday()
{
var request = new XMLHttpRequest();
request.open('GET', 'Menu3.json');
request.onreadystatechange = function() {
if ((request.readyState===4) && (request.status===200)) {
var menus = JSON.parse(request.responseText);
var output = " ";
for (var key in menus) {
output += "
}
var update = document.getElementById('menu');
update.innerHTML = output;
}
}
request.send();
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started