Asp.net asmx和aspx文件中WebMethod的不同声明?
在aspx文件和asmx文件中声明webmethod时,我有确切的代码。它们是为客户端脚本而公开的webmethods。我只想在asmx文件中使用webmethod,但无法使其工作 当我在aspx文件中引用一个方法时,一切正常,但当我在asmx中引用webmethod时,我收到一个未知的错误方法。我检查了“未知方法,参数methodname”的所有解决方案,但没有任何帮助 Webmethod以类似的方式声明:Asp.net asmx和aspx文件中WebMethod的不同声明?,asp.net,web-services,asmx,webservices-client,Asp.net,Web Services,Asmx,Webservices Client,在aspx文件和asmx文件中声明webmethod时,我有确切的代码。它们是为客户端脚本而公开的webmethods。我只想在asmx文件中使用webmethod,但无法使其工作 当我在aspx文件中引用一个方法时,一切正常,但当我在asmx中引用webmethod时,我收到一个未知的错误方法。我检查了“未知方法,参数methodname”的所有解决方案,但没有任何帮助 Webmethod以类似的方式声明: [WebMethod] public static string[] InsertRe
[WebMethod]
public static string[] InsertRecord(string param) { return something }
唯一的区别是asmx包含类的[System.Web.Script.Services.ScriptService]
我想不出是什么问题
正在从控件(ascx)中的Jquery脚本位置调用WebMethod
}您的web.config文件可能需要此文件(检查是否存在):
您需要在web.config文件中使用httppost和httpget,否则您的ajax调用将永远不会发生。您所说的“引用方法”是什么意思?显示您的代码。你想从哪里调用什么方法?@OndrejTucny我已经更新了我的代码解决方案是在方法声明中删除“static”。
function InsertRecord(notice)
{
$.ajax({
type: "POST",
url: "/Webservices/Records.asmx/InsertRecord",
data: "{ 'notice':'" + notice + '' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
},
error: function(msg) {}
});
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
</protocols>
</webServices>