Hi I'm trying to make an html file (no PHP allowed) that will send an ajax request to a server and then alert the response :
$(document).ready(function(){
$("#connect").click(function(){
$.ajax({
url: "http://213.74.86.200:8080/pwr/relays?ac=123456",
type: "GET",
crossDomain: true,
contentType: 'text/plain',
xhrFields: {
withCredentials: false
},
headers: {
'Access-Control-Allow-Origin': '*'
},
success:function(data,status){
if(status=="success"){
alert(data);
}else{
alert("Connection Error");
}
}
});
});
});
The thing is that when I open the link with my browser
http://213.74.86.200:8080/pwr/relays?ac=123456
everything works just fine and I can see the response as a text but when I open my html file and click the connect button I get this in the console log :
OPTIONS http://213.74.86.200:8080/pwr/relays?ac=123456
XMLHttpRequest cannot load http://213.74.86.200:8080/pwr/relays?ac=123456.
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'null' is therefore not allowed access. The response had
HTTP status code 405.
Any help please ?