Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

339
Views
PageController no se puede solicitar a través de XmlHttpRequest en Shopware 6

Estoy tratando de enviar una solicitud a mi StorefrontController personalizado en el último Shopware 6.2.2 pero recibo el siguiente error:

 PageController can't be requested via XmlHttpRequest.

Estoy haciendo una solicitud httpClient regular como tal desde un complemento JS personalizado:

 export default class MyCustomPlugin extends Plugin { static options = { dataUrl: '', // comes from the twig as "path('frontend.path.to.route')" product: null, params: {}, loadingIndicatorClass: 'is-loading', responseSelector: 'some-selector-class' } init () { // this.el.innerHTML = LoadingIndicator.getTemplate() this.httpClient = new HttpClient() const query = querystring.stringify(this.options.product) this.sendDataRequest(query) } /** * Add classes to add loading styling. * Prevents the user from clicking filter labels during filter request. */ addLoadingIndicatorClass () { this.el.classList.add(this.options.loadingIndicatorClass) } /** * Remove loading styling classes. */ removeLoadingIndicatorClass () { this.el.classList.remove(this.options.loadingIndicatorClass) } /** * Send request to get filtered product data. * * @param {String} filterParams - active filters as querystring */ sendDataRequest (filterParams) { this.addLoadingIndicatorClass() this.httpClient.abort() this.httpClient.get(`${this.options.dataUrl}?${filterParams}`, (response) => { this.renderResponse(response) this.removeLoadingIndicatorClass() }) } /** * Inject the HTML of the response to the element. * * @param {String} response - HTML response */ renderResponse (response) { ElementReplaceHelper.replaceFromMarkup(response, this.options.responseSelector, false) window.PluginManager.initializePlugins() } }

Y aquí está mi ruta StorefrontController :

 /** * @Route("/path/to_route", name="frontend.path.to.route", methods={"GET"}) */ public function someAction(Request $request, Context $context): JsonResponse

¿Alguien puede decirme por qué no va la solicitud? Quiero enviar una solicitud AJAX simple a mi propio controlador en Shopware 6.

¡Gracias!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Prueba con agregar:

defaults={"XmlHttpRequest"=true} a su ruta.

Así que después de los cambios tendrás:

 /** * @Route("/path/to_route", name="frontend.path.to.route", methods={"GET"}, defaults={"XmlHttpRequest"=true}) */

También asegúrese de que el alcance esté correctamente definido en el controlador mediante la anotación @RouteScope . Dado que su código es un complemento de JavaScript de escaparate, debe tener definido el alcance del storefront .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!