I tried to create this by following the video at http://www.asp.net/learn/videos/video-7026.aspx where Joe Stagner created a simple web service that is called with Ajax. In the Button1_onclick() handler, javascript can't resolve the object "WebService1". Do you see s anything wrong?
我尝试通过http://www.asp.net/learn/videos/video-7026.aspx上的视频创建此内容,其中Joe Stagner创建了一个使用Ajax调用的简单Web服务。在Button1_onclick()处理程序中,javascript无法解析对象“WebService1”。你觉得有什么不对吗?
The exact error is "'WebService1' is undefined" in Button1_onclick().
在Button1_onclick()中确切的错误是“'WebService1'未定义”。
Note: I took out the head and body tags so the post would display ok. They are all there in my file.
注意:我取出了头部和身体标签,因此帖子显示正常。它们都在我的文件中。
<script language="javascript" type="text/javascript">
function Button1_onclick() {
ret = WebService1.HelloWorld(document.getElementById("Text1").value, OnComplete, OnError);
}
function OnError() {
alert("An error occurred");
}
function OnComplete(arg) {
document.getElementById("CallResponse").innerHTML = arg;
}
</script>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/WebService1.asmx" />
</Services>
</asp:ScriptManager>
<div>
<input id="Text1" type="text" /><br /><br />
<input id="Button1" type="button" value="Click to test Ajax" onclick="return Button1_onclick()" /><br />
<div id="CallResponse">
</div>
</div>
</form>
Here's the web service. Yes, I un-commented the line I was supposed to.
这是网络服务。是的,我没有评论我本应该说的那条线。
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace AjaxTest { /// /// Summary description for WebService1 /// [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 WebService1 : System.Web.Services.WebService { [WebMethod] public string HelloWorld(string s) { return "Hello " + s; } } }
1 个解决方案
#1
It should look for AjaxTest.WebService1
as the class. It works off the fully qualified namespace
它应该将AjaxTest.WebService1作为类来查找。它使用完全限定的命名空间
#1
It should look for AjaxTest.WebService1
as the class. It works off the fully qualified namespace
它应该将AjaxTest.WebService1作为类来查找。它使用完全限定的命名空间