-1

I am using react and axios for post the data. and i want response in modal after post the data. currently i am getting data in console.log but i want to see these data in modal. currently i m using alert but getting undefined in alert.

axios.post("https://api_use.com/aof/upload/broker/existing/user/", data, options).then(res => { 
    console.log(res)
    this.setState({ avatar: res.data.url, uploadPercentage: 100 }, ()=>{
      setTimeout(() => {
        this.setState({ uploadPercentage: 0 })
      }, 1000);

      console.log(res.data.failed)

     **alert(console.log(res.data.failed));**
    })
})
govind jha
  • 107
  • 2
  • 11

1 Answers1

2

Console.log by definition only logs to the developer console. To display in an alert, simply remove the use of console.log:

alert(res.data.failed);

It is possible in JavaScript to redefine console.log (example), but this is an advanced use case that I would not recommend for the simple code you are showing above.

For a modal popup other than the standard alert, you'll probably want to install something like react-modal. For several variations on how to achieve this, see Rendering a modal in React

sfuqua
  • 5,797
  • 1
  • 32
  • 33