你好,我使用ajax和webservice将表单信息添加到数据库中:
网络服务代码是:
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
ajax是:
$.ajax({
type: "GET",
url: "WebService.asmx/HelloWorld",
data: {},
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
dataType: "text",
success: function (data) {
alert(date);
},
failure: function (msg) { alert("Sorry!!! "); }
});
但是,当我运行代码时,我会得到以下错误:
GET http://localhost:53145/Group/WebService.asmx/HelloWorld 500 (Internal Server Error)
有人能帮我吗?ajax代码和位于同一个文件夹中的webservice及其名称是否正确?
发布于 2014-11-20 03:14:34
您应该将其添加到web.config
文件中:
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
或将方法从GET
更改为POST
.ajax({
type: "POST",
url: "WebService.asmx/HelloWorld",
.....
发布于 2014-11-20 02:28:57
错误清楚地表明ajax请求无法确定webservice的路径。我建议使用浏览器调试工具来解决路径问题。只需按F12和调试模式打开。如需详细使用,请使用下面的链接。
http://forums.asp.net/t/1934215.aspx?Using+jQuery+ajax+to+call+asmx+webservice+methods
https://stackoverflow.com/questions/27036497
复制相似问题