I'm encountering an issue when attempting to send a request to my customized StorefrontController
on the most recent version of Shopware 6.2.2
. The error message I'm receiving is:
PageController can't be requested via XmlHttpRequest.
I'm making a standard httpClient
request from a custom JS plugin like this:
export default class MyCustomPlugin extends Plugin {
static options = {
dataUrl: '',
product: null,
params: {},
loadingIndicatorClass: 'is-loading',
responseSelector: 'some-selector-class'
}
init () {
this.httpClient = new HttpClient()
const query = querystring.stringify(this.options.product)
this.sendDataRequest(query)
}
addLoadingIndicatorClass () {
this.el.classList.add(this.options.loadingIndicatorClass)
}
removeLoadingIndicatorClass () {
this.el.classList.remove(this.options.loadingIndicatorClass)
}
sendDataRequest (filterParams) {
this.addLoadingIndicatorClass()
this.httpClient.abort()
this.httpClient.get(`${this.options.dataUrl}?${filterParams}`, (response) => {
this.renderResponse(response)
this.removeLoadingIndicatorClass()
})
}
renderResponse (response) {
ElementReplaceHelper.replaceFromMarkup(response, this.options.responseSelector, false)
window.PluginManager.initializePlugins()
}
}
Below is my StorefrontController
route:
/**
* @Route("/path/to_route", name="frontend.path.to.route", methods={"GET"})
*/
public function someAction(Request $request, Context $context): JsonResponse
I'm puzzled as to why the request is not working. I simply want to send a basic AJAX request to my controller in Shopware 6. Any insights would be greatly appreciated.
Thank you!