axios不发起请求,带有axios的POST请求未发送参数

I am trying to POST some data from Vue.js to a backend based on Symfony using the following code.

updateQuestion : function() {

axios.post('/staff/question/api/' + this.id,{

id : 'test',

name : 'sree'

})

.then( response => {

console.log(response);

})

.catch(error => {

console.log(error);

})

},

However, the parameters that I am attaching to the POST request are not reaching my controller. So, I tried the alternate format for POST requests and still, the parameters are not reaching the controller. Please tell me what's wrong.

Alternate format:

updateQuestion : function() {

axios({

method : 'POST',

url : '/staff/question/api/' + this.id,

data: {

id : 'test',

name : 'sree'

}

})

.then( response => {

console.log(response);

})

.catch(error => {

console.log(error);

})

},

解决方案

I also encountered this problem!

My post data was found in the controller:

$request->getContent();

My vue script

onSubmit() {

axios.post('/test/post/data', { test: "test" })

.then(response => {

console.log(response.data);

});

},

My Symfony controller:

public function postData(Request $request)

{

$data = $request->getContent();

$data = json_decode($data, true);

return $this->json($data);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值