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
ajax reactjs symfony axios
|
show 1 more comment
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
ajax reactjs symfony axios
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
|
show 1 more comment
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
ajax reactjs symfony axios
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
ajax reactjs symfony axios
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
|
show 1 more comment
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
|
show 1 more comment
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.
add a comment |
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??!!
This does not seem to be an answer. More like a second question? Big no no around here.
– Cerad
2 days ago
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered 2 days ago
iiirxs
2,3262926
2,3262926
add a comment |
add a comment |
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??!!
This does not seem to be an answer. More like a second question? Big no no around here.
– Cerad
2 days ago
add a comment |
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??!!
This does not seem to be an answer. More like a second question? Big no no around here.
– Cerad
2 days ago
add a comment |
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??!!
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??!!
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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