我有一个网络服务&我用jquery ajax调用它来调用它 该服务托管在一个同时承载silverlight项目的项目中 在web.config中,我有
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept, X-Requested-With" />
<add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>
端点配置
<service behaviorConfiguration="ThreeBirds.HttpServiceBehavior" name="TheWire.Server.Endpoints.LeadCaptureService">
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="AspNetAjaxBehavior" name="LeadCaptureService" contract="ThreeBirds.Services.Contracts.ILeadCaptureService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
和自定义行为配置
<behavior name="AspNetAjaxBehavior">
<enableWebScript />
</behavior>
所以当我从javascript调用webservice发布数据时,我得到'405方法不允许'错误
var webMethod = 'RecordSubscribe';
var formFields = {
dealerid: dealerID,
firstname: $(form).find(".inputFirstName").val(),
lastname: $(form).find(".inputLastName").val(),
email: $(form).find(".inputEmail").val()
};
$.ajax({
type: "POST",
url: "http://thewire.3birdsmarketing.com/wire/endpoints/Leadcapture.svc/Record" + webMethod,
processData: false,
contentType: "application/json",
data: JSON.stringify(formFields),
allowCrossDomain: true,
dataType: "json",
success: function (data, status, req) {
alert("Thank you " + formFields.firstname + " " + formFields.lastname + ", your information has been submitted.");
},
error: function (data) {
alert('Sorry ! There was an error sending your data. Please try it again.');
}
});
在Chrome中,该服务确实成功,但在IE(10)&amp; firefox(19)它失败了&amp;我收到错误消息。 Chrome首先执行OPTIONS请求,结果就像IE&amp; firefox但是在那之后chrome自动执行另一个POST请求&amp;提出了200. IE&amp; Firefox不会执行另一个POST请求。
我有什么遗漏的吗? 谢谢你的回答