Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Axios.put inside Axios.get

I want to update status, but when I want to do the 'put' it's not working cause axios in axios.put is not define. Can you help me please.

getAbsencesByRequestId(reqId) {
    axios.get(REQUESTID_URL + reqId).then(response => {
        this.collaboId = response.data[0].collabId; 
        this.beginDate = response.data[0].startDate;
        this.finishDate = response.data[0].endDate;
        this.reason = response.data[0].type;
    }, (error) => {
        console.log(error.response.status)
    }) axios.put(REQUEST_URL + reqId, {
        collabId: this.collaboId,
        startDate: this.beginDate,
        endDate: this.finishDate,
        status: 'VALIDATED',
        type: this.reason
    })
},
like image 811
Jinx59 Avatar asked Mar 09 '26 13:03

Jinx59


1 Answers

You should manage properly the order of your requests

axios.get(url /*optional payload and headers*/).then((getResponse) => {
  //do GET stuff with response
}).then(() => {
  //do PUT call
  axios.put(url, /*optional payload and headers*/).then((putResponse) => {
    //do PUT stuff with response
  })
}).catch((e) => {
  //handle the error
})
like image 117
Luis Mendoza Avatar answered Mar 12 '26 01:03

Luis Mendoza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!