Why does jQuery function throw an undefined error?http://forums.asp.net/t/1774834.aspx/1?Why+does+jQuery+function+throw+an+undefined+error+Wed, 29 Feb 2012 03:02:51 -050017748344855532http://forums.asp.net/p/1774834/4855532.aspx/1?Why+does+jQuery+function+throw+an+undefined+error+Why does jQuery function throw an undefined error? <p>I have a page that contains a single jQuery function:</p> <pre class="prettyprint">&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;ShowCometJQuery.aspx.cs&quot; Inherits=&quot;MetroLinx.Web.ShowCometJQuery&quot; %&gt; &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head runat=&quot;server&quot;&gt; &lt;title&gt;&lt;/title&gt; &lt;script type=&quot;text/javascript&quot; src=&quot;Scripts/jquery-1.7.1.js&quot; &gt; var xmlHttpRequestObject; function getResponse() { xmlHttpRequestObject = $.ajax({ url: &quot;http://L45723:1802&quot;, username: &quot;server&quot;, password: &quot;server123&quot;, async: true, contentType: &quot;application/xml&quot;, complete: function () { if (jqXHR.readyState == 4) { var msgDiv = document; var status = jqXHR.status; var txt = jqXHR.responseText; var xmldoc = new XMLDocument(); xmldoc.loadXML(txt); var messageNodes = xmldoc.getElementsByTagName(&quot;Message&quot;); var numMessages = messageNodes.length; for (i = 0; i &lt; numMessages; i&#43;&#43;) { var msgNode = messageNodes[i].text; document.getElementById(&quot;_receiveCometMsg&quot;).innerHTML &#43;= msgNode.toString(); } } } }); } &lt;/script&gt; &lt;/head&gt; &lt;body onload=&quot;getResponse()&quot;&gt; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt; &lt;div&gt; &lt;asp:Label runat=&quot;server&quot; ID=&quot;_receiveCometMsg&quot; /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p>It calls a COMET service which I wrote and posted here:</p> <p>http://derrickswebapps.codeplex.com</p> <p>However, when I load the page in the debugger, it keeps throwing a function not defined error. Why?</p> 2012-02-28T19:55:53-05:004855596http://forums.asp.net/p/1774834/4855596.aspx/1?Re+Why+does+jQuery+function+throw+an+undefined+error+Re: Why does jQuery function throw an undefined error? <p>are you sure jquery is load perfectly ?</p> <p>you can check into console tab in &nbsp;firebug or chrome using &nbsp;Inspect element.&nbsp;</p> <p></p> <p>i hope this help.</p> <p>Thanks</p> 2012-02-28T21:16:47-05:004855727http://forums.asp.net/p/1774834/4855727.aspx/1?Re+Why+does+jQuery+function+throw+an+undefined+error+Re: Why does jQuery function throw an undefined error? <p>Try reorganizing your script tags and see if that helps:</p> <pre class="prettyprint">&lt;script type=&quot;text/javascript&quot; src=&quot;Scripts/jquery-1.7.1.js&quot;&gt;&lt;/script&gt; &lt;script type=&quot;text/javascript&quot;&gt; var xmlHttpRequestObject; function getResponse() { xmlHttpRequestObject = $.ajax({ url: &quot;http://L45723:1802&quot;, username: &quot;server&quot;, password: &quot;server123&quot;, async: true, contentType: &quot;application/xml&quot;, complete: function () { if (jqXHR.readyState == 4) { var msgDiv = document; var status = jqXHR.status; var txt = jqXHR.responseText; var xmldoc = new XMLDocument(); xmldoc.loadXML(txt); var messageNodes = xmldoc.getElementsByTagName(&quot;Message&quot;); var numMessages = messageNodes.length; for (i = 0; i &lt; numMessages; i&#43;&#43;) { var msgNode = messageNodes[i].text; document.getElementById(&quot;_receiveCometMsg&quot;).innerHTML &#43;= msgNode.toString(); } } } }); } &lt;/script&gt;</pre> 2012-02-29T01:42:29-05:004855793http://forums.asp.net/p/1774834/4855793.aspx/1?Re+Why+does+jQuery+function+throw+an+undefined+error+Re: Why does jQuery function throw an undefined error? <p>nowhere do you define jqXHR. it shoudl be&nbsp;</p> <p>&nbsp; &nbsp;complete: function (jqXHR) {</p> <p>&nbsp; }<br> &nbsp;</p> <p>though it not clear why the readyState check. just use success which has already done the check. also why load a new xml dom, when jqXHR already has one? also if you just used success you could just write:</p> <p>&nbsp; success: function(xml) {<br> &nbsp; &nbsp; &nbsp;var html = &quot;&quot;;<br> &nbsp; &nbsp; &nbsp;&#36;.each(xml.getElementsByTagName(&quot;Message&quot;),function() {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; html&nbsp;&#43;= this.text;<br> &nbsp; &nbsp; &nbsp;});<br> &nbsp; &nbsp; &nbsp;&#36;(&quot;_receivingCometMsg&quot;).html(html);&nbsp;<br> &nbsp; }&nbsp;</p> <p>&nbsp; &nbsp;</p> <p></p> <p>&nbsp;&nbsp;</p> 2012-02-29T03:02:51-05:00