Hi. 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?
The exact error is "'WebService1' is undefined" in Button1_onclick().
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; } } }