Populate Native HTML Datalist with AJAX
How do I make an populate native html datalist with ajax?
A demo of how to populate a native HTML datalist field with AJAX. Using Rotten Tomatoes' Movie Search API. See where datalist is supported. What is a populate native html datalist with ajax? How do you make a populate native html datalist with ajax? This script and codes were developed by Joshua P. Larson on 23 July 2022, Saturday.
Populate Native HTML Datalist with AJAX - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Populate Native HTML Datalist with AJAX</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <input type="text" list="movies" data-movie-search placeholder="Start searching for a movie..." />
<datalist id="movies" data-movie-list></datalist> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Populate Native HTML Datalist with AJAX - Script Codes CSS Codes
body { background: #336699;
}
[data-movie-search] { border: 2px solid #efefef; font-size: 1.5em; display: block; width: 80%; padding: 1em; margin: 3rem auto;
}
Populate Native HTML Datalist with AJAX - Script Codes JS Codes
'use strict';
var MOVIE_SEARCH = { rtApiKey: '', rtApiEndpoint: '', delay: 0, timer: 0, input: {}, list: {}, init: function() { // Define elements this.input = $('[data-movie-search'); this.list = $('[data-movie-list]'); // Set delay this.delay = 300; // 300 milliseconds // Set Rotten Tomatoes data this.rtApiKey = 'jpe83dcf7beyxqn6gxwm2cwa'; this.rtApiEndpoint = 'http://api.rottentomatoes.com/api/public/v1.0/movies.json'; // Add event listeners this.input.on('keyup', this.setTimer.bind(this)); }, setTimer: function() { if ( this.timer ) { clearTimeout(this.timer); } this.timer = setTimeout( this.processQuery.bind(this), this.delay ); }, processQuery: function() { var query = this.input.val(); if ( ! query ) { return false; } $.ajax({ dataType: 'jsonp', url: this.rtApiEndpoint, data: { apikey: this.rtApiKey, q: query }, success: this.updateMovieList.bind(this) }); }, updateMovieList: function( response ) { if ( 'object' === typeof( response.movies ) ) { var movies = response.movies; // Clear the list this.list.html(''); $.each( movies, function(idx, movie) { this.list.append('<option>' + movie.title + '</option>'); }.bind(this)); } }
};
$(document).ready(function() { MOVIE_SEARCH.init();
});
Developer | Joshua P. Larson |
Username | jplhomer |
Uploaded | July 23, 2022 |
Rating | 3 |
Size | 2,763 Kb |
Views | 54,648 |
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 |
Hey React | 3,959 Kb |
Responsive HTML Timeline | 3,137 Kb |
Lightweight Quiz Widget | 4,596 Kb |
Webkit Text Masking | 1,975 Kb |
Displaying a Google Street View of your current location | 2,275 Kb |
Verge-Style Homepage Tiles | 5,147 Kb |
Fixed Nav HoverIntent Example | 4,444 Kb |
Animated Donut Chart | 3,808 Kb |
Seamless Scrolling Background | 2,535 Kb |
JS Geolocator | 2,653 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 |
Flower expansion | Sreucherand | 3,425 Kb |
FCC - Tribute Page | Cmwebby | 0 Kb |
Banner Ad | Raquellorenzana | 4,172 Kb |
Ionic Infinite outside ion-content with ion-pane | Felquis | 3,117 Kb |
Hovers with popups | Zacharyolson | 2,380 Kb |
Nav Test -- cats 1 | Payls | 4,735 Kb |
CSS-Flexbox-Demo | Sstiglets | 1,709 Kb |
JQuery AJAX reddit Exercise | Btholt | 1,777 Kb |
A Pen by Theun | Tjoen | 6,152 Kb |
Basic HTML5 Structure | YuvarajTana | 1,289 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!