Axios put request and symfony controller











up vote
1
down vote

favorite












Can you explain me why Axios request does not work in my Symfony application?



I use Axios request with React like this :



handleSubmit = () => {
axios.put('/families/' + this.props.familyId + '/edit',{
parents: "test"
})
.then(response => {
alert('Family has been modified');
})
};


My controller :



/**
* Edit Family
*
* @Route("families/{id}/edit", name="family_edit")
* @Method(methods={"PUT"})
* @param Request $request
* @param $id
*/
public function editFamilyAction(Request $request, $id)
{
$parents = $request->get('parents');

...
}


But $parents equals null...



What is happening, do I need some configuration somewhere?



Help needed please!



Denis










share|improve this question
























  • If you look at the request in the Network tab of your Developer Tools, is it showing any errors?
    – Tholle
    2 days ago










  • I have an error 500, because i do not return statement in my fonction. I do not return statement for now because my fonction is not finalised. Is it the problem? I debug it in PhpStorm.
    – Denis Ancelle
    2 days ago










  • I'm not quite sure. You could return some mock data in the meantime to rule out that that is not the issue.
    – Tholle
    2 days ago












  • Okay so I have tried and no error returned in Network tab...
    – Denis Ancelle
    2 days ago










  • Possible duplicate of Posting JSON objects to Symfony 2
    – mblaettermann
    2 days ago















up vote
1
down vote

favorite












Can you explain me why Axios request does not work in my Symfony application?



I use Axios request with React like this :



handleSubmit = () => {
axios.put('/families/' + this.props.familyId + '/edit',{
parents: "test"
})
.then(response => {
alert('Family has been modified');
})
};


My controller :



/**
* Edit Family
*
* @Route("families/{id}/edit", name="family_edit")
* @Method(methods={"PUT"})
* @param Request $request
* @param $id
*/
public function editFamilyAction(Request $request, $id)
{
$parents = $request->get('parents');

...
}


But $parents equals null...



What is happening, do I need some configuration somewhere?



Help needed please!



Denis










share|improve this question
























  • If you look at the request in the Network tab of your Developer Tools, is it showing any errors?
    – Tholle
    2 days ago










  • I have an error 500, because i do not return statement in my fonction. I do not return statement for now because my fonction is not finalised. Is it the problem? I debug it in PhpStorm.
    – Denis Ancelle
    2 days ago










  • I'm not quite sure. You could return some mock data in the meantime to rule out that that is not the issue.
    – Tholle
    2 days ago












  • Okay so I have tried and no error returned in Network tab...
    – Denis Ancelle
    2 days ago










  • Possible duplicate of Posting JSON objects to Symfony 2
    – mblaettermann
    2 days ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











Can you explain me why Axios request does not work in my Symfony application?



I use Axios request with React like this :



handleSubmit = () => {
axios.put('/families/' + this.props.familyId + '/edit',{
parents: "test"
})
.then(response => {
alert('Family has been modified');
})
};


My controller :



/**
* Edit Family
*
* @Route("families/{id}/edit", name="family_edit")
* @Method(methods={"PUT"})
* @param Request $request
* @param $id
*/
public function editFamilyAction(Request $request, $id)
{
$parents = $request->get('parents');

...
}


But $parents equals null...



What is happening, do I need some configuration somewhere?



Help needed please!



Denis










share|improve this question















Can you explain me why Axios request does not work in my Symfony application?



I use Axios request with React like this :



handleSubmit = () => {
axios.put('/families/' + this.props.familyId + '/edit',{
parents: "test"
})
.then(response => {
alert('Family has been modified');
})
};


My controller :



/**
* Edit Family
*
* @Route("families/{id}/edit", name="family_edit")
* @Method(methods={"PUT"})
* @param Request $request
* @param $id
*/
public function editFamilyAction(Request $request, $id)
{
$parents = $request->get('parents');

...
}


But $parents equals null...



What is happening, do I need some configuration somewhere?



Help needed please!



Denis







ajax reactjs symfony axios






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked 2 days ago









Denis Ancelle

235




235












  • If you look at the request in the Network tab of your Developer Tools, is it showing any errors?
    – Tholle
    2 days ago










  • I have an error 500, because i do not return statement in my fonction. I do not return statement for now because my fonction is not finalised. Is it the problem? I debug it in PhpStorm.
    – Denis Ancelle
    2 days ago










  • I'm not quite sure. You could return some mock data in the meantime to rule out that that is not the issue.
    – Tholle
    2 days ago












  • Okay so I have tried and no error returned in Network tab...
    – Denis Ancelle
    2 days ago










  • Possible duplicate of Posting JSON objects to Symfony 2
    – mblaettermann
    2 days ago


















  • If you look at the request in the Network tab of your Developer Tools, is it showing any errors?
    – Tholle
    2 days ago










  • I have an error 500, because i do not return statement in my fonction. I do not return statement for now because my fonction is not finalised. Is it the problem? I debug it in PhpStorm.
    – Denis Ancelle
    2 days ago










  • I'm not quite sure. You could return some mock data in the meantime to rule out that that is not the issue.
    – Tholle
    2 days ago












  • Okay so I have tried and no error returned in Network tab...
    – Denis Ancelle
    2 days ago










  • Possible duplicate of Posting JSON objects to Symfony 2
    – mblaettermann
    2 days ago
















If you look at the request in the Network tab of your Developer Tools, is it showing any errors?
– Tholle
2 days ago




If you look at the request in the Network tab of your Developer Tools, is it showing any errors?
– Tholle
2 days ago












I have an error 500, because i do not return statement in my fonction. I do not return statement for now because my fonction is not finalised. Is it the problem? I debug it in PhpStorm.
– Denis Ancelle
2 days ago




I have an error 500, because i do not return statement in my fonction. I do not return statement for now because my fonction is not finalised. Is it the problem? I debug it in PhpStorm.
– Denis Ancelle
2 days ago












I'm not quite sure. You could return some mock data in the meantime to rule out that that is not the issue.
– Tholle
2 days ago






I'm not quite sure. You could return some mock data in the meantime to rule out that that is not the issue.
– Tholle
2 days ago














Okay so I have tried and no error returned in Network tab...
– Denis Ancelle
2 days ago




Okay so I have tried and no error returned in Network tab...
– Denis Ancelle
2 days ago












Possible duplicate of Posting JSON objects to Symfony 2
– mblaettermann
2 days ago




Possible duplicate of Posting JSON objects to Symfony 2
– mblaettermann
2 days ago












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










It's simple as that:



/**
* @Route("/families/{id}/edit", name="family_edit", methods={"PUT"})
* @param Request $request
* @param $id
*/
public function editFamilyAction(Request $request, $id)
{

$data = $request->getContent();
$data = json_decode($data);
$parents = $data->parents;

// do your stuff
}


Note that if you are using Symfony 4, Method annotation has been deprecated, instead you should configure the Route annotation properly like I did in the code above.






share|improve this answer




























    up vote
    0
    down vote













    Wow it seems that it is working ! thanks you very very much guy!!



    Can you explain me what is my mistake please?



    I have just copy/pasted team code without success. Let me explain the code :



    React :



     handleSaveDiagnostic = () => {
    axios.put('/admin/api/diagnostic/update-diagnostic/'+ this.state.currentDiagnostic.id, {
    'newDiagnostic': this.state.currentDiagnostic
    })
    .then(response => {
    alert('Family has been modified');
    this.loadCounters();
    })
    };


    Controller :



    * @Route("/update-diagnostic/{diagnostic}", name="update_diagnostic")
    * @Method(methods={"PUT"})
    *
    * @param SymfonyComponentHttpFoundationRequest $request
    * @param AppBundleEntityDiagnostic $diagnostic
    *
    * @return SymfonyComponentHttpFoundationResponse
    */
    public function updateDiagnosticAction(Request $request, Diagnostic $diagnostic) {

    $newDiagnostic = $request->get('newDiagnostic'); (is working!)

    ...
    }


    What's the difference please, it is working for him but $request->getContent is needed for me??!!






    share|improve this answer























    • This does not seem to be an answer. More like a second question? Big no no around here.
      – Cerad
      2 days ago











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343604%2faxios-put-request-and-symfony-controller%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    It's simple as that:



    /**
    * @Route("/families/{id}/edit", name="family_edit", methods={"PUT"})
    * @param Request $request
    * @param $id
    */
    public function editFamilyAction(Request $request, $id)
    {

    $data = $request->getContent();
    $data = json_decode($data);
    $parents = $data->parents;

    // do your stuff
    }


    Note that if you are using Symfony 4, Method annotation has been deprecated, instead you should configure the Route annotation properly like I did in the code above.






    share|improve this answer

























      up vote
      0
      down vote



      accepted










      It's simple as that:



      /**
      * @Route("/families/{id}/edit", name="family_edit", methods={"PUT"})
      * @param Request $request
      * @param $id
      */
      public function editFamilyAction(Request $request, $id)
      {

      $data = $request->getContent();
      $data = json_decode($data);
      $parents = $data->parents;

      // do your stuff
      }


      Note that if you are using Symfony 4, Method annotation has been deprecated, instead you should configure the Route annotation properly like I did in the code above.






      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        It's simple as that:



        /**
        * @Route("/families/{id}/edit", name="family_edit", methods={"PUT"})
        * @param Request $request
        * @param $id
        */
        public function editFamilyAction(Request $request, $id)
        {

        $data = $request->getContent();
        $data = json_decode($data);
        $parents = $data->parents;

        // do your stuff
        }


        Note that if you are using Symfony 4, Method annotation has been deprecated, instead you should configure the Route annotation properly like I did in the code above.






        share|improve this answer












        It's simple as that:



        /**
        * @Route("/families/{id}/edit", name="family_edit", methods={"PUT"})
        * @param Request $request
        * @param $id
        */
        public function editFamilyAction(Request $request, $id)
        {

        $data = $request->getContent();
        $data = json_decode($data);
        $parents = $data->parents;

        // do your stuff
        }


        Note that if you are using Symfony 4, Method annotation has been deprecated, instead you should configure the Route annotation properly like I did in the code above.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        iiirxs

        2,3262926




        2,3262926
























            up vote
            0
            down vote













            Wow it seems that it is working ! thanks you very very much guy!!



            Can you explain me what is my mistake please?



            I have just copy/pasted team code without success. Let me explain the code :



            React :



             handleSaveDiagnostic = () => {
            axios.put('/admin/api/diagnostic/update-diagnostic/'+ this.state.currentDiagnostic.id, {
            'newDiagnostic': this.state.currentDiagnostic
            })
            .then(response => {
            alert('Family has been modified');
            this.loadCounters();
            })
            };


            Controller :



            * @Route("/update-diagnostic/{diagnostic}", name="update_diagnostic")
            * @Method(methods={"PUT"})
            *
            * @param SymfonyComponentHttpFoundationRequest $request
            * @param AppBundleEntityDiagnostic $diagnostic
            *
            * @return SymfonyComponentHttpFoundationResponse
            */
            public function updateDiagnosticAction(Request $request, Diagnostic $diagnostic) {

            $newDiagnostic = $request->get('newDiagnostic'); (is working!)

            ...
            }


            What's the difference please, it is working for him but $request->getContent is needed for me??!!






            share|improve this answer























            • This does not seem to be an answer. More like a second question? Big no no around here.
              – Cerad
              2 days ago















            up vote
            0
            down vote













            Wow it seems that it is working ! thanks you very very much guy!!



            Can you explain me what is my mistake please?



            I have just copy/pasted team code without success. Let me explain the code :



            React :



             handleSaveDiagnostic = () => {
            axios.put('/admin/api/diagnostic/update-diagnostic/'+ this.state.currentDiagnostic.id, {
            'newDiagnostic': this.state.currentDiagnostic
            })
            .then(response => {
            alert('Family has been modified');
            this.loadCounters();
            })
            };


            Controller :



            * @Route("/update-diagnostic/{diagnostic}", name="update_diagnostic")
            * @Method(methods={"PUT"})
            *
            * @param SymfonyComponentHttpFoundationRequest $request
            * @param AppBundleEntityDiagnostic $diagnostic
            *
            * @return SymfonyComponentHttpFoundationResponse
            */
            public function updateDiagnosticAction(Request $request, Diagnostic $diagnostic) {

            $newDiagnostic = $request->get('newDiagnostic'); (is working!)

            ...
            }


            What's the difference please, it is working for him but $request->getContent is needed for me??!!






            share|improve this answer























            • This does not seem to be an answer. More like a second question? Big no no around here.
              – Cerad
              2 days ago













            up vote
            0
            down vote










            up vote
            0
            down vote









            Wow it seems that it is working ! thanks you very very much guy!!



            Can you explain me what is my mistake please?



            I have just copy/pasted team code without success. Let me explain the code :



            React :



             handleSaveDiagnostic = () => {
            axios.put('/admin/api/diagnostic/update-diagnostic/'+ this.state.currentDiagnostic.id, {
            'newDiagnostic': this.state.currentDiagnostic
            })
            .then(response => {
            alert('Family has been modified');
            this.loadCounters();
            })
            };


            Controller :



            * @Route("/update-diagnostic/{diagnostic}", name="update_diagnostic")
            * @Method(methods={"PUT"})
            *
            * @param SymfonyComponentHttpFoundationRequest $request
            * @param AppBundleEntityDiagnostic $diagnostic
            *
            * @return SymfonyComponentHttpFoundationResponse
            */
            public function updateDiagnosticAction(Request $request, Diagnostic $diagnostic) {

            $newDiagnostic = $request->get('newDiagnostic'); (is working!)

            ...
            }


            What's the difference please, it is working for him but $request->getContent is needed for me??!!






            share|improve this answer














            Wow it seems that it is working ! thanks you very very much guy!!



            Can you explain me what is my mistake please?



            I have just copy/pasted team code without success. Let me explain the code :



            React :



             handleSaveDiagnostic = () => {
            axios.put('/admin/api/diagnostic/update-diagnostic/'+ this.state.currentDiagnostic.id, {
            'newDiagnostic': this.state.currentDiagnostic
            })
            .then(response => {
            alert('Family has been modified');
            this.loadCounters();
            })
            };


            Controller :



            * @Route("/update-diagnostic/{diagnostic}", name="update_diagnostic")
            * @Method(methods={"PUT"})
            *
            * @param SymfonyComponentHttpFoundationRequest $request
            * @param AppBundleEntityDiagnostic $diagnostic
            *
            * @return SymfonyComponentHttpFoundationResponse
            */
            public function updateDiagnosticAction(Request $request, Diagnostic $diagnostic) {

            $newDiagnostic = $request->get('newDiagnostic'); (is working!)

            ...
            }


            What's the difference please, it is working for him but $request->getContent is needed for me??!!







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited yesterday

























            answered 2 days ago









            Denis Ancelle

            235




            235












            • This does not seem to be an answer. More like a second question? Big no no around here.
              – Cerad
              2 days ago


















            • This does not seem to be an answer. More like a second question? Big no no around here.
              – Cerad
              2 days ago
















            This does not seem to be an answer. More like a second question? Big no no around here.
            – Cerad
            2 days ago




            This does not seem to be an answer. More like a second question? Big no no around here.
            – Cerad
            2 days ago


















             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343604%2faxios-put-request-and-symfony-controller%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]