1
当我尝试从$.ajax
方法调用wcf服务时,我收到以下异常。405方法不允许 - 当使用jquery ajax方法调用wcf服务
1. Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
2. Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the requested resource.
AJAX编码
$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(request),
async: false,
url: "http://localhost:65201/Empservice.svc/getEmployee",
crossdomain: true,
success: function (data) {
try {
response = data;
}
catch (e) {
alert(e);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Excpetion " + errorThrown + XMLHttpRequest);
}
});
网址是不正确的使用网址:“您的网址” – kamesh
[请在这里阅读](http://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work) – StuartLC
您提出请求跨域但是您将dataType定义为JSON。更改为JSONP,如果您尝试访问您的本地主机文件,请在您的url内部提及您的IP地址:url“yourIpAddress/Empservice.svc/getEmployee” – kamesh