写一个能实现manticore search搜索功能的html页面
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Manticore Search</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
<h1>Manticore Search</h1>
<form id="searchForm">
<input type="text" id="searchQuery" placeholder="Enter your search query">
<input type="submit" value="Search">
</form>
<pre><code><div id="searchResults"></div>
<script>
$(document).ready(function() {
$('#searchForm').submit(function(event) {
event.preventDefault();
var query = $('#searchQuery').val();
$.ajax({
url: 'https://your-manticore-search-server/search',
type: 'GET',
data: { q: query },
dataType: 'json',
success: function(data) {
displayResults(data);
},
error: function() {
alert('An error occurred while performing the search.');
}
});
});
function displayResults(data) {
$('#searchResults').empty();
if (data.hits.total > 0) {
for (var i = 0; i < data.hits.hits.length; i++) {
var result = data.hits.hits[i];
var title = result._source.title;
var content = result._source.content;
var resultItem = '<div class="result">' +
'<h3>' + title + '</h3>' +
'<p>' + content + '</p>' +
'</div>';
$('#searchResults').append(resultItem);
}
} else {
$('#searchResults').html('<p>No results found.</p>');
}
}
});
</script>
</code></pre>
</body>
</html
原文地址: https://www.cveoy.top/t/topic/im3W 著作权归作者所有。请勿转载和采集!