Example call using jQuery for predictive search is not working

Highlighted
Explorer
78 7 12

In this article

https://shopify.dev/docs/themes/ajax-api/reference/predictive-search

there is an example of a JQuery call

jQuery.getJSON("/search/suggest.json", {
"q": "jacket",
"resources": {
"type": "product",
"limit": 4,
"options": {
"unavailable_products": "last",
"fields": "title,product_type,variants.title"
}
}
}).done(function(response) {
var productSuggestions = response.resources.results.products;

if (productSuggestions.length > 0) {
var firstProductSuggestion = productSuggestions[0];

alert("The title of the first product suggestion is: " + firstProductSuggestion.title);
}
});

If I put this in between script tags <script> and </script>, right above the closing body tag </body>, nothing happens when I open the page. I should get an alert right?

I cheked if JQuery is implemented with the following code

if (window.jQuery) { 
// jQuery is loaded 
alert("Yeah!");
} else {
// jQuery is not loaded
alert("Doesn't Work");
}

I get the Yeah alert. 

My website is menschenskinder-shop.de and the password vuffey

I use the minimal theme.

I'd be very happy about help here. I just don't know why I can't do a JQuery call. Thank you!! 

0 Likes