我正在尝试调用网络服务。 webservice和调用代码都在同一个项目中。当 javascript 函数尝试调用 Web 服务函数 AttnCcc.saveAttnCcc 时,出现错误:Microsoft JScript 运行时错误:'AttnCcc' 未定义
以下代码在调用服务的aspx文件中:
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="AttnCcc.asmx.cs" />
</Services>
</asp:ScriptManager>
在同一个 aspx 文件中,我试图从以下 js 函数调用它:
<script type="text/javascript">
function ConfirmCcc(ID, webDataGridName) {
AttnCcc.saveAttnCcc("44,duplicate,this test data");
}
</script>
Web 服务是以下 asmx.cs 文件:
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
namespace are
{
/// <summary>
/// Summary description for AttnCcc
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class AttnCcc : System.Web.Services.WebService
{
[ScriptMethod]
[WebMethod]
public void saveAttnCcc(string ccc)
{
string cblCccText, tbCccText;
int Id;
string[] arr = ccc.Split(',');
Id = int.Parse(arr[0]);
cblCccText = arr[1]; tbCccText = arr[2];
}
}
我做错了什么?
最佳答案
您不能调用 void 类型的网络服务。
我更改为返回一个我从未使用过的 int 并且调用 js 能够找到它。
public int saveAttnCcc(string ccc) {
...
return dummyInt;
}
关于javascript - 试图在我的应用程序中调用网络服务但未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5137180/