Test Case for ajax fail on single result v2
How do I make an test case for ajax fail on single result v2?
Trying to identify why this code works when the json data returned has multiple items but generates an undefined error for json data with a single item.. What is a test case for ajax fail on single result v2? How do you make a test case for ajax fail on single result v2? This script and codes were developed by Martin Boyce on 20 September 2022, Tuesday.
Test Case for ajax fail on single result v2 - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Test Case for ajax fail on single result v2</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'>
</head>
<body> <div class="container-fluid page-wrap"> <section id="main" class="main row" role="main"> <div class="col-xs-12"> <h1>RSS to HTML via JSON</h1> <p class="lead">New Items Lists generated from RSS feeds that are fetched through Yahoo Query Language (YQL) to provide a JSON feed.</p> </div> <div id="sidebar" class="col-sm-3"> <div id="newItemsSelector" class="panel-group new-items-selector" role="tablist" aria-multiselectable="true"> <div class="panel panel-default"> <div class="panel-heading" role="tab" id="fiction"> <h3 class="panel-title"> <a role="button" data-toggle="collapse" data-parent="#newItemsSelector" href="#collapseFiction" aria-expanded="true" aria-controls="collapseFiction">Load JSON</a> </h3> </div> <div id="collapseFiction" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="fiction"> <ul class="list-group"> <li class="list-group-item"><a id="newyafiction" class="loader" href="https://webpac.sutherlandshire.nsw.gov.au/screens/newyafiction.html" data-feed="newyafiction">click to load multiple json results</a></li> <li class="list-group-item"><a id="newjuniordvds" class="loader" href="https://webpac.sutherlandshire.nsw.gov.au/screens/newjuniordvds.html" data-feed="newjuniordvds">click to load single json result</a></li> </ul> </div> </div><!-- /panel --> </div><!-- /new-items-selector --> </div><!-- /sidebar --> <div id="content" class="col-sm-9 content"> <div id="newItemsData" class="new-items-data"> <h2></h2> <p id="jsonSource"></p> <p id="subscribe" class="lead"> Source: <a id="jsonSubscribe" class="btn btn-info btn-xs" target="_blank">json</a> <a id="rssSubscribe" class="btn btn-warning btn-xs" target="_blank">RSS</a> </p> <div id='newItems' class='new-items'></div> </div> </div><!-- /content --> </section>
</div><!-- /container --> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Test Case for ajax fail on single result v2 - Script Codes JS Codes
$(document).ready(function() { function generatePanels(title, url, description, isbn) { if (description !== undefined) { $('<div class="panel panel-default"><div class="panel-heading"><h3 class="panel-title"><a target="_blank" href="' + url + '">' + title + '</a></h3></div><div class="panel-body">' + description + '<br>' + isbn + '</div></div>').appendTo("#newItems"); } else { $('<div class="panel panel-default"><div class="panel-heading"><h3 class="panel-title"><a target="_blank" href="' + url + '">' + title + '</a></h3></div><div class="panel-body">' + isbn + '</div></div>').appendTo("#newItems"); } } function populateList(feedName) { var xmlSource = 'https://webpac.sutherlandshire.nsw.gov.au/feeds/' + feedName + '.xml'; var jsonSource = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%3D'http%3A%2F%2Fwebpac.sutherlandshire.nsw.gov.au%2Ffeeds%2F" + feedName + ".xml'&format=json&callback=?"; //fetch the json feed $.getJSON(jsonSource, function() { console.log('json request:' + jsonSource); console.log('success'); }) .done(function(data) { console.log('retrieved JSON data'); $('#newItemsData > h2').text('URL to fetch json'); $('#jsonSource').text(jsonSource); $('#jsonSubscribe').attr('href', jsonSource); $('#rssSubscribe').attr('href', xmlSource); $('#newItems').empty(); //if there are items in the data generate an <li> for each if (data.query.count === 1) { var $title = data.query.results.item.title; var $url = data.query.results.item.link; var $description = data.query.results.item.description; var $isbn = data.query.results.item.guid.content.split(' ', 1); generatePanels($title, $url, $description, $isbn); } else if (data.query.count > 1) { $.each(data.query.results.item, function(i, book) { var $title = book.title; var $url = book.link; var $description = book.description; var $isbn = book.guid.content.split(' ', 1); generatePanels($title, $url, $description, $isbn); }); } else { // if the json request is successful but there are no items console.log('no data retrieved'); } $('.new-items-data').fadeIn('slow'); }) .fail(function() { //if the fetch fails reveal the error alert .new-items-fail console.log('fail'); }) .error(function() { //if the fetch fails reveal the error alert .new-items-fail console.log('error'); }); }; $('.loader').on('click', function(event) { //call the function that generates the list var $feedId = $(this).data('feed'); populateList($feedId); //prevent the default action on the link in the btn event.preventDefault(); });
});
Developer | Martin Boyce |
Username | boycetrus |
Uploaded | September 20, 2022 |
Rating | 3 |
Size | 3,313 Kb |
Views | 16,192 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Homepage thumbnail | 1,852 Kb |
Google Maps API test | 4,057 Kb |
Google Maps API Custom Overlay | 3,336 Kb |
Sutherland Shire Libraries Catalogue Search | 2,732 Kb |
Google Maps API Ground Overlay | 2,961 Kb |
Test Case for ajax fail on single result | 3,297 Kb |
AJAX content from an RSS feed using jQuery | 3,878 Kb |
Nested flexbox layout for library catalog v2 | 3,409 Kb |
Using Google Spreadsheets as JSON Source | 2,492 Kb |
Get the app | 3,198 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Nested table email layout | Massimo-cassandro | 2,355 Kb |
Slider for stackoverflow | KKOKU | 3,222 Kb |
Ball Physics | Getsetbro | 3,149 Kb |
Menubar compass mixin | Michaelparenteau | 4,925 Kb |
Use the Twitchtv JSON API | Roksanaop | 3,561 Kb |
Background Images | Jooonebug | 2,100 Kb |
Ripples in water | Nobitagit | 2,704 Kb |
NgEasyModal | Lorenzodianni | 4,159 Kb |
A Pen by Mohomed Anees | Mohomedanees | 12,597 Kb |
Resizable SASS Icons | Marianarlt | 7,611 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!