In: Computer Science
If the data object's success property is true, display the first todo item from data. Otherwise, display the error from data.
function responseReceivedHandler(data) {
/* Successful request:
{
"success": true,
"todos": [ '...', '...', ... ]
}
Unsuccessful request:
{
"success": false,
"error": "..."
} */
/* Your solution goes here */
}
$.get("https://wp.zybooks.com/todos.php", { day: "Monday" }, responseReceivedHandler, "json");
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ function responseReceivedHandler(data) { /* Successful request: { "success": true, "todos": [ '...', '...', ... ] } Unsuccessful request: { "success": false, "error": "..." } */ if(data.success) { alert(data.todos[0]); } else { alert('Request errored out.') } } $.get("https://wp.zybooks.com/todos.php", { day: "Saturday" }, responseReceivedHandler, "json"); }); </script> </head> <body> </body> </html>
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.