0

I am attempting to make a call to the Web Purify API to check profanity in certain text.

function webPurifyAPi(string){
    const Http = new XMLHttpRequest();
    const url="http://www.webpurify.com/services/rest/?method=webpurify.live.check&api_key=apiKEY&lang=en&format=json&text="+string;
    Http.open("GET",url);
    Http.send();

    Http.onreadystatechange=(e)=>{
        console.log(this.responseText);
    }   
    fetch(url).then(response => response.json()).then(data => {
        if(data.error_messages) {
            throw new Error(data.error_message);
        }
        console.log(data);
    });
}

I keep getting this error when I attempt to run the function.

No 'Access-Control-Allow-Origin' header is present on the requested resource.

I need to just get the response in json format to check if profanity is found? Am I attempting to do this correctly?

  • 3
    That error means that the API is not intended to be used from client code. You have to create a server-side proxy to access it. – Pointy Aug 07 '18 at 14:49
  • 1
    Do you want to use `fetch` or do you want to use `XMLHttpRequest`? Don't try both. – Bergi Aug 07 '18 at 14:51

0 Answers0