I want to wait for my axios function to continue executing so I can get the url from the response before executing my code further. How can I wait for the promise to resolve?
for (i = 0; i < responseArray.length; i++) {
if(responseArray[i].id === "text"){
var id = responseArray[i].firstChild.firstChild.id
responses.push({
type : 'text',
data : $("#" + id).val()
})
}
else if(responseArray[i].id === "image"){
var fileID = responseArray[i].firstChild.firstChild.firstChild.firstChild.firstChild.lastChild.id
console.log(fileID)
var file = $('#'+fileID)[0].files[0]
var formData = new FormData()
formData.append('file',file)
formData.append('upload_preset',preset)
console.log(formData)
axios({
url: uploadURL,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data:formData,
}).then(function(res) {
responses.push({
type : 'image',
data : res.data.url
})
}).catch(function(err){
console.log(err)
})
}
}
data = {}
data.responses = responses
console.log(data.responses)
I wanna store the responses in my data object. But it doesnt wait for axios to stop executing.