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

244
Views
Why in ajax with symfony 5 ,the controller don't recognize the ajax call?

My problem:

I post by ajax at my controller the form.

$.ajax({
    url: "test.php",
    type: "post",
    data: new FormData(document.querySelector("form")) ,
    success: function (response) {

       // You will get response from your PHP page (what you echo or print)
    },
    error: function(jqXHR, textStatus, errorThrown) {
       console.log(textStatus, errorThrown);
    }
});

and my controller

<?php

namespace  App\Controller;
/*¤controller_namespace¤*/

use ...

/**
 * @Route("admin/article")
 */ class ArticleController extends AbstractController
{


    /**
     * @Route("/upload", name="upload", methods={"GET","POST"})
     */
    public function upload(Request $request, FileUploader $fileUploader): Response
    {
        /*¤new_begin¤*/
        $article = new Article();
        $form = $this->createForm(ArticleType::class, $article);

        $form->handleRequest($request);
        /*¤new_form¤*/
        //return error for ajax only
        if ($request->isXmlHttpRequest() && !$form->isValid()) {
            return new jsonResponse(getErrorMessages($form), 415);
        }
    }}

Symfony don't detect the ajax call in the controller. I send a form invalid but the function isXmlHttpRequest don't detect the ajax call.

about 4 years ago · Juan Pablo Isaza
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!