【发布时间】:2017-01-29 14:54:31
【问题描述】:
我正在尝试从 html 和 ajax 脚本调用在 wcf 中实现的 post 方法。 我可以从 postman 调用。我尝试了 google , stackoverflow previous questions ,但没有一个对我有帮助。
我来自 wcf 的 web.config :
<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint name="" crossDomainScriptAccessEnabled="true" />
</webScriptEndpoint>
</standardEndpoints>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET,POST,DELETE,HEAD,PUT,OPTIONS" />
</customHeaders>
</httpProtocol>
以下是我在html中的ajax调用
$.ajax({
type: "POST",
url: "http://localhost:8078/SportsClubDefault.svc/Validate",
data: st,
contentType: "application/json; charset=utf-8",
processData:true,
dataType: "json",
success: function (data) {
// Play with response returned in JSON format
alert('Login success');
},
error: function (xhr) {
alert('Login failed');
}
});
【问题讨论】: