javascript - how can I send an object using axios? -
is there way send object api using axios?
this code use:
axios.get('/api/phones/create/', { parameters: { phone: this.phone } }) .then(response => { console.log(response.data) }) .catch(function (error) { console.log(error) })
on the php side, have following:
public function create($phone) { return $phone; }
i following error:
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 status code 500 @ createerror (app.6007af59798a7b58ff81.js:600) @ settle (app.6007af59798a7b58ff81.js:742) @ xmlhttprequest.handleload (app.6007af59798a7b58ff81.js:158)
if try, axios.get('/api/phones/create/hello')
hello
in console log.
is there way this?
it depends on mean "send object".
since you're using request , passing object in parameters, can serialize query params part of request. wouldn't send object more use build query section of url request.
for example, here's how can make request /api/phones/create?phone=123
:
axios.get('/api/phones/create/', { params: { phone: '123' } })
if want send object serialized json api, can use post or put request, depending on semantics of api.
for example, send { "phone": "123" }
api, do:
axios.post('/api/phones/create/', { phone: '123' });
note: axios expects key params
parameters.
Comments
Post a Comment