我想使用对象发送一个get请求。服务器上将使用该对象数据来更新会话数据。但是由于如果我尝试将其发送回打印出来,就只会得到:
"N;"
我可以使用jQuery这样做,并且它有效:
$.get('/mysite/public/api/updatecart', { 'product': this.product }, data => {
console.log(data);
});
使用 Laravel 从服务器返回的对象如下所示:
public function updateCart(Request $request){
return serialize($request->product);
使用axios不会产生同样的效果:
axios.get('/api/updatecart', { 'product': this.product })
.then(response => {
console.log(response.data);
});
我使用axios设置了一个默认的baseURL,所以url与之前不同。它正确地到达了api端点,并返回了被发送的内容,但显然不是对象。我只得到了<N>作为结果。