Avatar of Steve Tinsley
Steve Tinsley
Flag for United Kingdom of Great Britain and Northern Ireland

asked on 

Simple ajax with cross domain error

I want to be able to fire a simple HTML request using ajax.
I don't have access to change the server I am requesting, but all it does is fire back OK as plain text if all is ok.

Here is my super simple code:

<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>




         url: "",
         success: function(data)

            if (data == "ok") {
            } else {
               alert("not ok :( - " + data);
         error: function(jqXHR, textStatus, errorThrown)
            console.log("Oops: " + textStatus + errorThrown);

      return false;





<div id="div1"></div>



Open in new window

The issue is that i get an error response:

Access to XMLHttpRequest at '' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
untitled.html:36 Oops: error

When I look at the network tab in Chrome I still get the OK back....

Is there a way to avoid this error??

Avatar of undefined
Last Comment
Steve Tinsley

8/22/2022 - Mon