HeIIo, I'm trying to create a small service, that would add some functionality to a webpage. The user inserts the following code on his website.
<script src="http://mywebsite.com/code.js"></script>
The purpose of this code is loading of an html element with the following request:
$.ajax({
url: "http://mywebsite.com/element.html",
method: 'GET',
contentType: 'text/plain',
xhrFields: {
withCredentials: false
},
headers: {
},
success: function(data) {
$('body').append(data);
}
});
The problem is that I always get Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://mywebsite.com/element.html. This can be fixed by moving the resource to the same domain or enabling CORS.
I tried recommendations from this tutorial, but still getting the same errors. I also put the following row in .htaccess file: Header set Access-Control-Allow-Origin "*"
- still no result. I would appreciate any recommendations on how else I can enable CORS.