Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

Axios's response, what's in it??.....const response = await axios

I'm using Axios in WP e.g.

const response = await axios.delete(universityData.siteURL + "/wp-json/wp/v2/note/" + thisNote.getAttribute("data-noteID"))

All works fine but what I don't understand is the structure / content of 'response'. How do I interrogate 'response'? I had assumed for instance if I did console.log('Axios response: ' + response.data) I'd get a nicely laid out JSON like OO output in the Chrome console panel. But all I see is: Axios response: [object Object]

I can do this response.data.userNoteCount and I get something sensible back. BTW 'userNoteCount' is a field I added to my JSON for my custom post type. But how else do I see all the content of response without specifically having to target it?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Thanks to another contributor elsewhere this is the answer:

When you do the console.log you're adding the JSON object to the string of Axios Response, so the JSON object is being converted to a string, hence the object Object.

If you do it as two seperate lines, like

console.log('Axios Response'); console.log(response.data);

Then it will be outputted as the actual object.

With it being an HTTP Request though, rather than outputting it into the console, what I'd do is open the Network tab of the browser development tools, and select the XHR tab, and then the request will appear in there and you can inspect the full response body there without having to log it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...