【发布时间】:2016-03-27 05:24:29
【问题描述】:
这是我的 ajax 代码:
var param = "<ClientOrder xmlns='http://www.eysnap.com/mPlayer'>";
param += "<ClientId>CRF-1</ClientId>";
param += "<UserKey>598zxc8ddl45a3cvScuk</UserKey>" ;
param += "<PassKey>p1re254l3jd83os00cpk</PassKey>";
param += "<OrderId>123132323435</OrderId>";
param += "</ClientOrder>";
$.ajax({
url: URL,
data: param,
type: 'POST',
contentType: "text/xml",
dataType: "text",
success: function(result){
alert('success');
$("#div1").html(result);
},
error: function (xhr) {
alert('error');
$("#div1").html(xhr.responseText);
}
});
我正在调用的服务很安静。疯狂的是,当我调用 GET 服务时,它会正确返回数据,但使用 POST 服务时会出现此错误:
XMLHttpRequest cannot load [url]. Response for preflight has invalid HTTP status code 405
任何帮助将不胜感激。
【问题讨论】:
-
服务提供者决定方法,而不是调用者。如果提供为
get,则您必须遵守。它可能不符合 REST,但就是这样 :-) -
HTTP Error 405 Method not allowed这意味着他们不允许 POST 请求。 -
实际上不,那是另一个允许 GET 的服务。该服务是专门为 POST 提供的。我需要发送一个 POST 请求。
-
@YvoCilon:这不可能。我已经在 C# 代码中使用 POST 调用此服务。现在,当我尝试使用 JQuery 执行此操作时,它不起作用!
-
CORS 问题 ... 如果站点不允许 CORS,则站点不允许 CORS ... 服务器 -> 服务器将工作,浏览器 -> 服务器将要求在服务器上启用 CORS
标签: javascript ajax wcf-rest