how do i fix this error about POST net::ERR_CONNECTION_REFUSED

Viewed 871

when i post ajax, error occurs. enter image description here these are my codes.

let xhr = new XMLHttpRequest()
let data ={
      "name": "test",
      "phone": "12345678",
      "email": "test@test.com",
      "content": "i wish"
    }
let dataStr = JSON.stringify(data)
xhr.open('post',apiUrl,true) // apiUrl is provided from back side
xhr.setRequestHeader('Content-type','application/json')
xhr.send(dataStr)

it has bothered me few days,please help me.

2 Answers

This error indicates that the web application is not available / not running. To verify it, create a manually post request via postman or similar apps directly into the API to check the connection.

ERR_CONNECTION_REFUSED is due to when code cant access the given url, it is due to various reasons

  1. Firewall blocking
  2. Url may be down
  3. Internet issue etc

Try checking it while accessing it manually or through the postman or just put a try catch block in your code, it will give you exact status.

Related