A few days back I followed Andrew Connell’s excellent guide to adding Azure Search to a Hugo based website. Things weren’t totally plain sailing. I had to make the following changes to Andrew’s steps:
-
I was getting a javascript error: referenceerror $ is not defined . I tracked this down to the JQuery script not already being included in my site. This was resolved by adding the necessary
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
to the top of search.html. -
After this I was getting CORS errors in the javascript console which were resolved through setting Allowed Origin Type to All in the CORS tab of the Azure Search Index definition.
-
After this the javascript was running through to completion, and through variable inspection I could see that the search results were being returned, however the results were not being displayed. This was resolved by removing the space between
.container
and.searchresults
in this line:$(".container .search-results").html(render)