ajax调用webservice报错,有时说webservice找不到,有时说没定义的方法
webservice代码:Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Web.Script.Services
' この Web サービスを、スクリプトから ASP.NET AJAX を使用して呼び出せるようにするには、次の行のコメントを解除します。
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
<System.Web.Script.Services.ScriptService()> _
Public Class HelloService
Inherits System.Web.Services.WebService
<WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function
End Class
javascript代码:
Dim strScript As New StringBuilder
strScript.Append("function GetService(){")
strScript.Append(" HelloService.HelloWorld(CallBack);")
strScript.Append("}")
Me.Page.ClientScript.RegisterClientScriptBlock(Me.Page.GetType(), "GetService", strScript.ToString, True)
Dim strCallBack As New StringBuilder
strCallBack.Append("function CallBack(result){")
strCallBack.Append(" alert(result);")
strCallBack.Append("}")
Me.Page.ClientScript.RegisterClientScriptBlock(Me.Page.GetType(), "CallBack", strCallBack.ToString, True)
Me.myBtn.OnClientClick = "GetService()"
.aspx部分代码:
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
<Services >
<asp:ServiceReference Path ="http://localhost:2061/HelloService.asmx" />
</Services>
</asp:ScriptManager>
补充:.NET技术 , ASP.NET