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 |
Verge-Style Homepage Tiles | 5,147 Kb |
Hey React | 3,959 Kb |
Responsive HTML Timeline | 3,137 Kb |
Animated Donut Chart | 3,808 Kb |
CSS-Only Art Direction | 4,086 Kb |
Fixed Nav HoverIntent Example | 4,444 Kb |
Populate Native HTML Datalist with AJAX | 2,763 Kb |
Displaying a Google Street View of your current location | 2,275 Kb |
JS Geolocator | 2,653 Kb |
Lightweight Quiz Widget | 4,596 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 |
TestTube CSS | EZPK | 2,710 Kb |
Wave Lines | Mikehobizal | 4,023 Kb |
Vanilla JS - A toggleClass function | Woodwork | 2,532 Kb |
Background Images | Jooonebug | 2,100 Kb |
A Pen by Anoop | Anoopjohn | 330,760 Kb |
CSS3 Media Queries demo | Machal | 1,824 Kb |
PNotify Demo | Adittmar | 1,731 Kb |
Video mute | Leon9208 | 2,131 Kb |
See Through | Larrygeams | 77,410 Kb |
Right Click Menu | Anodpixels | 2,252 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!