samedi 17 juillet 2021

One function of my webpage has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource

One function of my webpage has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

What should I do with this error, thanks?

Webpage code:

<html>        
<tr>
         <td id="Bot_trap"> 
           <script type="text/javascript"> botQuestion(); </script>
         </td> 
         <td>Answer: <input id="Answer_please" name="human_answer" type="text" size="3" 
                      title="So that we know you are not a bot."></td>
       </tr>

</html> 

botQuestion() code:

function botQuestion() {
  var req = false;
  req = new XMLHttpRequest();
  if( !req ) {
    return "I could not create an XMLHttpRequest object.";
  }
  
  req.onreadystatechange = function() {
    if( req.readyState == 4 && req.status == 200 ) {
      var question = req.responseText;
      showQuestion(question);
    }
  }
  
  urlInc = url_get_question;  
  req.open("GET", urlInc, true);
  req.send(null);
} // end botQuestion()


function showQuestion(question) {
  document.getElementById("Bot_trap").innerHTML 
    = "<b>What is " + question + "? *</b>";
} // end showQuestion()



Aucun commentaire:

Enregistrer un commentaire