有沒有辦法使用axios將對象發送到API?如何使用axios發送對象?
該代碼使用:
axios.get('/api/phones/create/', {
parameters: {
phone: this.phone
}
})
.then(response => {
console.log(response.data)
})
.catch(function (error) {
console.log(error)
})
在PHP端,我有以下幾點:
public function create($phone)
{
return $phone;
}
我收到以下錯誤:
GET http://crm2.dev/api/phones/create 500 (Internal Server Error)
dispatchXhrRequest @ app.6007af59798a7b58ff81.js:256
xhrAdapter @ app.6007af59798a7b58ff81.js:93
dispatchRequest @ app.6007af59798a7b58ff81.js:662
app.6007af59798a7b58ff81.js:2266 Error: Request failed with status code 500
at createError (app.6007af59798a7b58ff81.js:600)
at settle (app.6007af59798a7b58ff81.js:742)
at XMLHttpRequest.handleLoad (app.6007af59798a7b58ff81.js:158)
如果我嘗試,axios.get('/api/phones/create/hello')
我在控制檯日誌中獲得hello
。
有沒有辦法做到這一點?
我不能肯定,但'請求與狀態代碼的失敗500'說,這是服務器端的問題,錯誤的 – Leguest
一部分確實是在PHP的方法:我這樣做,而不是:'公共函數來創建(請求$請求)' – Warrio