Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

muazzamazaz's avatar

Getting Object Promise on axios call return

function getWagon(para){

return ( 
axios.get('/op1_get_list/'+para).then((response) => {
return (response.data);
})
)

}

"Object Promise"

0 likes
5 replies
muazzamazaz's avatar

@SilenceBringer

async function getWagon(wagon){
return (await Promise.resolve(axios.get('/op1_get_wagon/'+wagon).then((response) => {
return (response.data.tankno);
})))
}

still same error

AungHtetPaing__'s avatar

@muazzamazaz how about this

async function getWagon(wagon){
	const response = await axios.get('/op1_get_wagon/'+wagon);
	return response.data.tankno;
}
Lumethys's avatar

@muazzamazaz

the 'then()-> chaining is intended to use the response in a callback function, which mean pretty much that you would only use it right in that function and nowhere else

if you want to reuse the data, you must assign it to a variable:

let response = await axios.get('blablabla');

Please or to participate in this conversation.