Fcojriosbello Fcojriosbello - 3 months ago 13
Javascript Question

XML response from fetch

I'm using

fetch
in a react-native app. I'm trying to read the response but when I use an
alert(response)
I get
[object Object]
. I've tried with other modules such as xml2js, react-native-html-parser', or xmldom.

fetch(
/*
REQUEST CONFIGURATION
*/
}).then(response => {
alert(response) // This is what returns [object Object]
})

Answer

Handle the response like this:

.then(response => {
      response.text().then(text => {
        // handle response content
        })
      })