You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A client has an Element API endpoint set up to return quick "as you type" search results. This works beautifully from the Craft site (https://example.com).
The client also has a subdomain powered by HubSpot (https://learn.example.com), and they want the same functionality across both sites. But when I copy over the same exact JS, the returned response is supposedly a 404, even though the JSON payload is identical.
Any ideas on why it's not working from a subdomain? I do have Access-Control-Allow-Origin defined properly, and I do see the difference it makes when it's there vs not there...
JS search functionality (on the HubSpot subdomain site):
functiondelay(fn,ms){lettimer=0returnfunction(...args){clearTimeout(timer)timer=setTimeout(fn.bind(this, ...args),ms||0)}}letsearchAutocompleteInputs=document.querySelectorAll('.jsSearchAutocomplete');searchAutocompleteInputs.forEach(input=>{letautocompleteId=input.dataset.list;letautocomplete=document.getElementById(autocompleteId);input.addEventListener('input',delay(function(e){letkeyword=e.target.value;if(keyword){fetch('https://example.com/api/search'+`?query=${keyword}`,{mode: 'cors'}).then((response)=>{console.log({response});if(response.ok){returnresponse.json();}thrownewError('Something went wrong with the fetch');}).then((responseJson)=>{// blah blah...}).catch((error)=>{console.warn(error);});}// Empty search fieldelse{autocomplete.innerHTML='';}},500));});
Description
A client has an Element API endpoint set up to return quick "as you type" search results. This works beautifully from the Craft site (
https://example.com
).The client also has a subdomain powered by HubSpot (
https://learn.example.com
), and they want the same functionality across both sites. But when I copy over the same exact JS, the returned response is supposedly a 404, even though the JSON payload is identical.Any ideas on why it's not working from a subdomain? I do have
Access-Control-Allow-Origin
defined properly, and I do see the difference it makes when it's there vs not there...element-api.php
JS search functionality (on the HubSpot subdomain site):
"404" response from Hubspot site:
Valid response from the Craft site:
Additional info
The text was updated successfully, but these errors were encountered: