Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript won't recognize web service
    text
    copied!<p>I tried to create this by following the video at <a href="http://www.asp.net/learn/videos/video-7026.aspx" rel="nofollow noreferrer">http://www.asp.net/learn/videos/video-7026.aspx</a> 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? </p> <p>The exact error is "'WebService1' is undefined" in Button1_onclick().</p> <p>Note: I took out the head and body tags so the post would display ok. They are all there in my file.</p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt; 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; } &lt;/script&gt; &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt; &lt;Services&gt; &lt;asp:ServiceReference Path="~/WebService1.asmx" /&gt; &lt;/Services&gt; &lt;/asp:ScriptManager&gt; &lt;div&gt; &lt;input id="Text1" type="text" /&gt;&lt;br /&gt;&lt;br /&gt; &lt;input id="Button1" type="button" value="Click to test Ajax" onclick="return Button1_onclick()" /&gt;&lt;br /&gt; &lt;div id="CallResponse"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>Here's the web service. Yes, I un-commented the line I was supposed to.</p> <pre> 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; } } } </pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload