使用jQuery发布到ASMX时出现405错误? [英] 405 error when POSTing to ASMX using jQuery?
问题描述
我们尝试过的事情:
-
ProtocolSupportModule已更新为所有动词。
ProtocolSupportModule has been updated to All verbs.
DNS是外部的可见。
DNS is externally visible.
启用匿名身份验证。
添加标题:
< customHeaders>
< add name =" Cache-Control"值= [否缓存" />
< add name =" Access-Control-Allow-Origin" value =" http://s-alg.cengage .com" />
< add name =" Access-Control-Allow-Headers" value =" Origin,X-Requested-With,Content-Type,Accept,X-PINGOTHER" />
< add name =" Access-Control-Allow-Methods" value =" POST,GET,OPTIONS,HEAD" />
< add name =" Access-Control-Max-Age"值= QUOT; 1000" />
< / customHeaders>
<customHeaders> <add name="Cache-Control" value="no-cache" /> <add name="Access-Control-Allow-Origin" value="http://s-alg.cengage .com" /> <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept, X-PINGOTHER" /> <add name="Access-Control-Allow-Methods" value="POST, GET, OPTIONS, HEAD" /> <add name="Access-Control-Max-Age" value="1000" /> </customHeaders>
我不确定下一步该尝试什么。希望与Web.config有关。
I’m not sure what to try next. Hopefully is something to do with Web.config.
推荐答案
该方法必须使用[WebInvoke]进行修饰以启用POST方法。
The method has to be decorated with [WebInvoke] to enable POST method.
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
更新:
如果它是asmx,在web.config中包含以下协议
If it is asmx, include the below protocols in web.config
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
in system.web
in system.web
此外,使用[scriptmethod]装饰web方法,从脚本
Also, decorate the web method with [scriptmethod] to be accessed from script
这篇关于使用jQuery发布到ASMX时出现405错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!