I have configured mongoosastic successfully, I tried searching and it is working fine, but when it comes to front-end I'm not really sure on how to achieve this, I experimented with a lot of ways but couldn't come up with a good solution.
Here's the code.
// For the Search API
router.post('/api/search/', function(req, res, next) {
Job.search(
{
query_string:
{ query: req.body.search }
} , function(err, results) {
if (err) return next(err);
res.json(results);
});
});
So whenever I search something that is related to 'engineer', I will get a json data
So the backend does working perfectly.
However when it comes to jquery and ajax I keep getting bad request
The logic: whenever something is inserted then post that and find that result.
Here's the frontend jquery code.
$('#search').keyup(function() {
var search_term = $(this).val();
$.ajax({
type: "POST",
url: "/api/search",
success: function(){
$('search_results').html(search_term);
},
error: function(data){
alert('Error', data);
}
});
});
HTML
<input type="text" class="form-control input-lg" id="search" name="search" placeholder="Search for part-time..." />
<div id="search_results">
</div>
How do I insert the json results to search_results
?