【发布时间】:2016-02-29 18:03:36
【问题描述】:
您好,我正在尝试制作一个 html 文件(不允许使用 PHP),它将向服务器发送一个 ajax 请求,然后提醒响应:
$(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");
}
}
});
});
});
问题是当我用浏览器打开链接时
http://213.74.86.200:8080/pwr/relays?ac=123456
一切正常,我可以将响应视为文本,但是当我打开我的 html 文件并单击连接按钮时,我在控制台日志中得到了这个:
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.
有什么帮助吗?
【问题讨论】:
标签: javascript jquery html ajax