jQuery ASP.net Web 服务消耗
我一直在研究如何使用下面的代码使用 $.ajax 调用来使用 webmethod:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/HelloWorld",
data: "{}",
dataType: "json",
success: function(msg) {
alert(msg.d);
}
});
但是,当我尝试将类型从“POST”更改为“GET”时,调用没有通过。有人可以指出发生这种情况的原因吗?
I have been looking on how to consume a webmethod using the $.ajax call using this code below:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/HelloWorld",
data: "{}",
dataType: "json",
success: function(msg) {
alert(msg.d);
}
});
However when I tried to change the type from "POST" to "GET", the call didn't go through. Can someone please point out a reason why this happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
默认情况下,ASP.Net AJAX Web 服务禁用
GET
请求,ScottGu 在这方面有一篇出色的博客文章,包括如何绕过该安全性(如果是这样的话)你在追求什么。下面是一个修复示例,通过设置 <
ScriptMethodAttribute< 上的代码>UseHttpGet
/代码>:By degault
GET
requests are disabled for ASP.Net AJAX Web services, ScottGu has an excellent blog entry on this, including how to bypass that security if that's what you're after.Here's an example fix, by setting
UseHttpGet
on theScriptMethodAttribute
:正如 Nick 所写,您可以使用 ScriptMethodAttribute 或在 web.config 中启用 GET 请求处理:
As Nick wrote you can use
ScriptMethodAttribute
or you can enableGET
request processing in web.config:您是否尝试过检查服务器端代码以查看它从哪里提取值?根据所使用的方法,它可能不会响应。
顺便说一句:如果您从 Web 服务检索数据,逻辑上正确的方法通常是 GET。
have you tried checking the server side code to see where it pulls values from? it may not respond depending on the method used.
also an aside: if you are retrieving data from a web service, the logically correct method is usually GET.