Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
API loading failed

As I said to my previous i am making a dictionary extencion in chrome so now I reached javascript part .In order to get words data I need to load an api so I used p5.js library because it's easier to load json data but I am confused with the syntax and I run in to errors.What should I do?

Here is my javascript code:

 var Dict;

    var button = document.getElementById("sub").onclick = submit;

    function submit() {

      var word = document.getElementById("input").value;

      var url = "https://api.dictionaryapi.dev/api/v2/entries/en/" + word;
      console.log(url)
      loadJSON(url, gotData)

    }

    function gotData(data) {
      Dict = data;


    }

    function draw() {

      if (Dict) {

        var resulttest = Dict[1]
        console.log(resulttest)


      }



    }

here is also my html code if its helpfull:

<html lang="en"><head>
    <link rel="stylesheet" href="style.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/addons/p5.sound.min.js"></script>

<script src="background.js" defer=""></script>

</head>
<body>
  <div class="wrapper"> Write a word :

    <input id="input" type="text"><br>
    <div>hello</div><br>
    <button id="sub">Submit</button>

</div> 

</body></html>

And this are the errors:

Refused to load the script 'https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/addons/p5.sound.min.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

popup.html:1 Refused to load the script 'https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/addons/p5.sound.min.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Testing youre code above, the main thing I can see missing is setup() which initializes a lot of p5 internals. You can place an empty setup() function then loadJSON() should work:

var dictionaryApiResult;

var button = document.getElementById("sub").onclick = submit;

function setup(){
 //to use loadJSON you still need to allow p5 to setup first
 //even though you're not using it's rendering or createInput()/createButton()
}

function submit() {

  var word = document.getElementById("input").value;

  var url = "https://api.dictionaryapi.dev/api/v2/entries/en/" + word;
  console.log(url)
  loadJSON(url, gotData)

}

function gotData(data) {
  dictionaryApiResult = data;
  console.log(dictionaryApiResult[1]);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>
<input type="text" id="input"><br>
<input type="submit" id="sub">

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!