<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Dev Pages &#187; Javascript and AJAX</title>
	<atom:link href="http://www.n8williams.com/devblog/category/javascript_and_ajax/feed" rel="self" type="application/rss+xml" />
	<link>http://www.n8williams.com/devblog</link>
	<description>A knowledge base for simple (and beyond) web applications development</description>
	<lastBuildDate>Fri, 21 May 2010 12:30:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>&#8216;Length&#8217; attribute or column name in database can clash with jQuery and javascript</title>
		<link>http://www.n8williams.com/devblog/javascript_and_ajax/length-attribute-or-column-name-in-database-can-clash-with-jquery-and-javascript</link>
		<comments>http://www.n8williams.com/devblog/javascript_and_ajax/length-attribute-or-column-name-in-database-can-clash-with-jquery-and-javascript#comments</comments>
		<pubDate>Thu, 13 May 2010 05:45:01 +0000</pubDate>
		<dc:creator>Nate Admin</dc:creator>
				<category><![CDATA[Javascript and AJAX]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.n8williams.com/devblog/?p=276</guid>
		<description><![CDATA[In what was one of the worst bugs I have come across in a while, mainly my fault, I learned the hard way that using the name &#8216;length&#8217; for an object attribute may be a bad idea. Along the same lines as using &#8216;window&#8217; as an attribute name. These things tend to cause clashes in [...]]]></description>
			<content:encoded><![CDATA[<p>In what was one of the worst bugs I have come across in a while, mainly my fault, I learned the hard way that using the name &#8216;length&#8217; for an object attribute may be a bad idea. Along the same lines as using &#8216;window&#8217; as an attribute name. These things tend to cause clashes in framework and javascript libraries.</p>
<p>So more specifically with the yii framework, which uses jQuery to handle gridview filtering, I debugged the hell out of other people&#8217;s JavaScript code until I learned from line 59 on the jQuery core library that the each method on a jQuery object uses the length property of a jQuery and javascript object to iterate over its properties.</p>
<p>It goes as follows. Say I have a &#8216;windowdrape&#8217; table and object. This has a length and width, in inches, of how big the drape is. So I make a &#8216;length&#8217; column. The yii framework hands my model object off to javascript. So now in javascript I have a windowdrape object. So WindowDrape.length to jQuery is how many attributes the WindowDrape has. I expect it to be how long the window is in inches. So I set it to 98, and now all of a sudden jQuery will iterate the thing 98 times, and the attributes on WindowDrape are all messed up because of the bogus length attribute. </p>
<p>The lesson here, especially if you use the yii framework is Don&#8217;t name a column or model object attribute &#8216;length&#8217;. These things are also why I avoid using &#8216;name&#8217; or &#8216;window&#8217; etc. for attribute names. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.n8williams.com/devblog/javascript_and_ajax/length-attribute-or-column-name-in-database-can-clash-with-jquery-and-javascript/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Dialog not showing content after being hidden</title>
		<link>http://www.n8williams.com/devblog/javascript_and_ajax/jquery-dialog-not-showing-content-after-being-hidden</link>
		<comments>http://www.n8williams.com/devblog/javascript_and_ajax/jquery-dialog-not-showing-content-after-being-hidden#comments</comments>
		<pubDate>Fri, 16 Jan 2009 01:37:59 +0000</pubDate>
		<dc:creator>Nate Admin</dc:creator>
				<category><![CDATA[Javascript and AJAX]]></category>

		<guid isPermaLink="false">http://www.n8williams.com/devblog/?p=59</guid>
		<description><![CDATA[So the autoOpen:false on the jQuery dialog instantiation doesn&#8217;t hide the div fast enough sometimes. You can skirt this by setting the display to none (display:none) on the dialog div you made, but then when you actually do load up the dialog after someone clicks an anchor, or whatever, the content of the div doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>So the autoOpen:false on the jQuery dialog instantiation doesn&#8217;t hide the div fast enough sometimes. You can skirt this by setting the display to none (display:none) on the dialog div you made, but then when you actually do load up the dialog after someone clicks an anchor, or whatever, the content of the div doesn&#8217;t show up because the child divs have all inherited the display:none;</p>
<p>Just call the show method after the dialog load to skirt this.</p>
<p>$(&#8221;#detailPopin&#8221;).dialog(&#8217;open&#8217;);<br />
$(&#8221;#detailPopin&#8221;).show();</p>
]]></content:encoded>
			<wfw:commentRss>http://www.n8williams.com/devblog/javascript_and_ajax/jquery-dialog-not-showing-content-after-being-hidden/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Error: &#8216;jQuery.event.special[...].teardown&#8217; is null or not an object</title>
		<link>http://www.n8williams.com/devblog/javascript_and_ajax/error-jqueryeventspecialteardown-is-null-or-not-an-object</link>
		<comments>http://www.n8williams.com/devblog/javascript_and_ajax/error-jqueryeventspecialteardown-is-null-or-not-an-object#comments</comments>
		<pubDate>Mon, 27 Oct 2008 19:03:18 +0000</pubDate>
		<dc:creator>Nate Admin</dc:creator>
				<category><![CDATA[Javascript and AJAX]]></category>

		<guid isPermaLink="false">http://www.n8williams.com/devblog/?p=51</guid>
		<description><![CDATA[Apparently, when the page is left, jQuery tries to remove event listeners. When this happens, the jQuery.event.special[type].teardown is null or undefined in a line of the jQuery source. This appears to be a dialog error, or caused by the dialog somehow. The jQuery error is found on line 1948 using the latest release, 1.2.6. (For [...]]]></description>
			<content:encoded><![CDATA[<p>Apparently, when the page is left, jQuery tries to remove event listeners. When this happens, the jQuery.event.special[type].teardown is null or undefined in a line of the jQuery source. This appears to be a dialog error, or caused by the dialog somehow. The jQuery error is found on line 1948 using the latest release, 1.2.6. (For me this is line 1955 but my jQuery has been a little modified).</p>
<p>I added the following to the if on line 1948 &#8211; || !jQuery.event.special[type].teardown. This fixes the jQuery error on line 1948.</p>
<div class="text-box"><code>if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem)<br />
 === false ) {</code></div>
<p>becomes</p>
<div class="text-box"><code>if ( !jQuery.event.special[type] || !jQuery.event.special[type].teardown<br />
 || jQuery.event.special[type].teardown.call(elem) === false ) {</code></div>
<p>This makes it so if the teardown function is undefined, an error won&#8217;t occur.</p>
<p>I am fairly certain that this fix doesn&#8217;t break anything else, but no guarantees. I didn&#8217;t spend a lot of time going into what elem.removeEventListener or elem.detatchEvent does because it looks like the eventListeners are not very consequential. Maybe a little bit more overhead. All I know is when I added the extra if, things worked great from that point on. And what I call a jQuery error could very well be an IE error, a user error (me, of course), etc. I happen to love jQuery.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.n8williams.com/devblog/javascript_and_ajax/error-jqueryeventspecialteardown-is-null-or-not-an-object/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery Dialog error in IE7. Runtime error: invalid argument</title>
		<link>http://www.n8williams.com/devblog/javascript_and_ajax/jquery-dialog-error-in-ie7-runtime-error-invalid-argument</link>
		<comments>http://www.n8williams.com/devblog/javascript_and_ajax/jquery-dialog-error-in-ie7-runtime-error-invalid-argument#comments</comments>
		<pubDate>Thu, 31 Jul 2008 17:35:52 +0000</pubDate>
		<dc:creator>Nate Admin</dc:creator>
				<category><![CDATA[Javascript and AJAX]]></category>

		<guid isPermaLink="false">http://www.n8williams.com/devblog/?p=44</guid>
		<description><![CDATA[So if your using jQuery UI dialogs, you may run into issues with IE 7. Apparently the value of a usually &#8216;undefined&#8217; javascript variable can get set to &#8216;NaNpx&#8217; in IE7. I had to change the jQuery base code to get a dialog ui component to work.
I was getting the following runtime error: &#8220;Line: 1102 [...]]]></description>
			<content:encoded><![CDATA[<p>So if your using jQuery UI dialogs, you may run into issues with IE 7. Apparently the value of a usually &#8216;undefined&#8217; javascript variable can get set to &#8216;NaNpx&#8217; in IE7. I had to change the jQuery base code to get a dialog ui component to work.</p>
<p>I was getting the following runtime error: &#8220;Line: 1102 Error: invalid argument.&#8221;</p>
<p>This error comes from code around line 1101 in jquery-1-2-6.js.</p>
<p>So I think my version of jQuery had already been modified or comes from an older or different source. My code follows, but the most recent 1-2-6 jQuery script has code that is like the comment Dom left (thanks &#8211; that code looks more like the most recent release of jQuery).</p>
<div class="text-box"><code>/* MODIFIED 7/31/08 BY NATE<br />
* WAS THIS, but IE7 was throwing an error<br />
if ( value != undefined )<br />
elem[ name ] = value;<br />
*/<br />
if ( value != 'NaNpx' &amp;&amp; value != undefined)<br />
elem[ name ] = value; //NATE - Sometimes the value would come up as NaNpx in<br />
IE and causes an error</code></div>
<p><a href="http://www.n8williams.com/devblog/wp-content/uploads/2008/07/jqueryerror.png"><img class="aligncenter size-full wp-image-45" title="jqueryerror" src="http://www.n8williams.com/devblog/wp-content/uploads/2008/07/jqueryerror.png" alt="jquery runtime error for dialog" width="269" height="176" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.n8williams.com/devblog/javascript_and_ajax/jquery-dialog-error-in-ie7-runtime-error-invalid-argument/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>With Internet Explorer, Javascript setAttribute(&#8217;style&#8217;, &#8217;something&#8217;) doesn&#8217;t work in IE</title>
		<link>http://www.n8williams.com/devblog/javascript_and_ajax/javascript-setattributestyle-something-doesnt-work-in-ie</link>
		<comments>http://www.n8williams.com/devblog/javascript_and_ajax/javascript-setattributestyle-something-doesnt-work-in-ie#comments</comments>
		<pubDate>Thu, 03 Jul 2008 18:08:11 +0000</pubDate>
		<dc:creator>Nate Admin</dc:creator>
				<category><![CDATA[Javascript and AJAX]]></category>

		<guid isPermaLink="false">http://www.n8williams.com/devblog/?p=40</guid>
		<description><![CDATA[If you try and set the style attribute of a DOM element with Javascript, the following code WON&#8217;T WORK IN IE:
yourelement.setAttribute('style','left:150px; top:150px;');
Instead use:
yourelement.style.cssText = 'left:150px; top:150px;';
Thanks to Rob on this page
http://www.quirksmode.org/bugreports/archives/2005/03/setAttribute_does_not_work_in_IE_when_used_with_th.html
http://blog.throbs.net/
]]></description>
			<content:encoded><![CDATA[<p>If you try and set the style attribute of a DOM element with Javascript, the following code WON&#8217;T WORK IN IE:</p>
<div class="text-box"><code>yourelement.setAttribute('style','left:150px; top:150px;');</code></div>
<p>Instead use:</p>
<div class="text-box"><code>yourelement.style.cssText = 'left:150px; top:150px;';</code></div>
<p>Thanks to Rob on this page</p>
<p><a title="http://www.quirksmode.org/bugreports/archives/2005/03/setAttribute_does_not_work_in_IE_when_used_with_th.html#c1759" href="http://www.quirksmode.org/bugreports/archives/2005/03/setAttribute_does_not_work_in_IE_when_used_with_th.html#c1759" target="_blank">http://www.quirksmode.org/bugreports/archives/2005/03/setAttribute_does_not_work_in_IE_when_used_with_th.html</a></p>
<p><a title="http://blog.throbs.net/" href="http://blog.throbs.net/" target="_blank">http://blog.throbs.net/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.n8williams.com/devblog/javascript_and_ajax/javascript-setattributestyle-something-doesnt-work-in-ie/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Javascript &#8211; Find height, position of scroll height in browser &#8211; great site</title>
		<link>http://www.n8williams.com/devblog/javascript_and_ajax/javascript-find-position-of-height-in-browser-scroll-height-great-site</link>
		<comments>http://www.n8williams.com/devblog/javascript_and_ajax/javascript-find-position-of-height-in-browser-scroll-height-great-site#comments</comments>
		<pubDate>Thu, 03 Jul 2008 17:26:37 +0000</pubDate>
		<dc:creator>Nate Admin</dc:creator>
				<category><![CDATA[Javascript and AJAX]]></category>

		<guid isPermaLink="false">http://www.n8williams.com/devblog/?p=38</guid>
		<description><![CDATA[For finding scroll height while being cross-browser compatible. This site was perfect for what I was doing.
http://www.codehouse.com/javascript/articles/scroll_area/
]]></description>
			<content:encoded><![CDATA[<p>For finding scroll height while being cross-browser compatible. This site was perfect for what I was doing.</p>
<p><a title="http://www.codehouse.com/javascript/articles/scroll_area/" href="http://www.codehouse.com/javascript/articles/scroll_area/" target="_blank">http://www.codehouse.com/javascript/articles/scroll_area/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.n8williams.com/devblog/javascript_and_ajax/javascript-find-position-of-height-in-browser-scroll-height-great-site/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javascript substring is not a function &#8211; check your variable content</title>
		<link>http://www.n8williams.com/devblog/javascript_and_ajax/javascript-substring-is-not-a-function-check-your-variable-content</link>
		<comments>http://www.n8williams.com/devblog/javascript_and_ajax/javascript-substring-is-not-a-function-check-your-variable-content#comments</comments>
		<pubDate>Tue, 24 Jun 2008 16:44:34 +0000</pubDate>
		<dc:creator>Nate Admin</dc:creator>
				<category><![CDATA[Javascript and AJAX]]></category>

		<guid isPermaLink="false">http://www.n8williams.com/devblog/?p=30</guid>
		<description><![CDATA[You&#8217;re trying to get the substring of a number, or something else, maybe undefined. 
trimAll(document.getElementById(&#8221;email&#8221;).value.length)
should be
trimAll(document.getElementById(&#8221;email&#8221;)).value.length
]]></description>
			<content:encoded><![CDATA[<p>You&#8217;re trying to get the substring of a number, or something else, maybe undefined. </p>
<p>trimAll(document.getElementById(&#8221;email&#8221;).value.length)</p>
<p>should be</p>
<p>trimAll(document.getElementById(&#8221;email&#8221;)).value.length</p>
]]></content:encoded>
			<wfw:commentRss>http://www.n8williams.com/devblog/javascript_and_ajax/javascript-substring-is-not-a-function-check-your-variable-content/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beware the affect of the base href= on AJAX requests, and IE. Permission denied to call XMLHttpRequest open method</title>
		<link>http://www.n8williams.com/devblog/javascript_and_ajax/beware-the-affect-of-the</link>
		<comments>http://www.n8williams.com/devblog/javascript_and_ajax/beware-the-affect-of-the#comments</comments>
		<pubDate>Fri, 30 May 2008 13:54:30 +0000</pubDate>
		<dc:creator>Nate Admin</dc:creator>
				<category><![CDATA[Javascript and AJAX]]></category>

		<guid isPermaLink="false">http://www.n8williams.com/devblog/?p=17</guid>
		<description><![CDATA[The base href effect on XMLHtttpRequest.open (in IE)
Imagine that. If your base href is set to something weird, the ajax requests will get Access errors indicating &#8220;Permission Denied to call method yourXMLHttpRequestObject.open&#8221; Errors! But only in IE.
In IE, with AJAX requests, your url root must match your base href. base ref=&#8221;http://www.mydomain.com should be the same [...]]]></description>
			<content:encoded><![CDATA[<h3>The base href effect on XMLHtttpRequest.open (in IE)</h3>
<p>Imagine that. If your base href is set to something weird, the ajax requests will get Access errors indicating &#8220;Permission Denied to call method yourXMLHttpRequestObject.open&#8221; Errors! But only in IE.</p>
<p>In IE, with AJAX requests, your url root must match your base href. base ref=&#8221;http://www.mydomain.com should be the same as the base url in xmlHttp.open(&#8221;GET&#8221;, &#8220;http://www.mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?<br />
method=getOrderInfoXML&#038;userid=1234&#8243;, true), or you can use relative urls.</p>
<p>Example I had:</p>
<div class="text-box">
<code>//The XMLHttpRequest is named xmlHttp here, xmlHttp = new XMLHttpRequest()<br />
//If the base href is set to something other than the server root, the AJAX request<br />
//thinks the request is coming from a different server, or something.<br />
//Permission denied to call XMLHttp.open with the following<br />
//SET IN HTML HEAD &lt;base href="http://www.mydomain.com/index.cfm?event=myOrder" /&gt;	 - NOT HTTPS!<br />
xmlHttp.open("GET", "https://mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?<br />
method=getOrderInfoXML&amp;userid=1234" , true);</p>
<p>//Now when the base href is set to the server root, no problems<br />
//SET IN HTML HEAD &lt;base href="https://www.mydomain.com/"&gt; - HTTP!<br />
xmlHttp.open("GET", "https://mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?<br />
method=getOrderInfoXML&amp;userid=1234" , true);		</code>
</div>
<h3>Issues when www isn&#8217;t mapped to your home url</h3>
<p>Another issue that can happen with access denied errors with your AJAX request is when your www doesn&#8217;t resolve to the same url as your root. I.E. http://www.yourdomain.com isn&#8217;t the same dns entry as http://ourdomain.com, even if they both eventually go to the same server ip.</p>
<p>Error: Happens when your session is in http://www.yourdomain.com and your AJAX request points to http://yourdomain.com (if your www subdomain doesn&#8217;t resolve to http://yourdomain.com).</p>
<div class="text-box">
<code>//I'm on a http:://www.mydomain.com page, and I get an error with this line<br />
xmlHttp.open("GET", "http://mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?<br />
method=getOrderInfoXML&amp;userid=1234" , true);<br />
// I'm on a http:://mydomain.com page, this line will work<br />
xmlHttp.open("GET", "http://mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?<br />
method=getOrderInfoXML&amp;userid=1234" , true);	</code>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.n8williams.com/devblog/javascript_and_ajax/beware-the-affect-of-the/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript variable names and &#8216;missing ; before statement&#8217;</title>
		<link>http://www.n8williams.com/devblog/javascript_and_ajax/javascript-variable-names</link>
		<comments>http://www.n8williams.com/devblog/javascript_and_ajax/javascript-variable-names#comments</comments>
		<pubDate>Thu, 22 May 2008 18:17:07 +0000</pubDate>
		<dc:creator>Nate Admin</dc:creator>
				<category><![CDATA[Javascript and AJAX]]></category>

		<guid isPermaLink="false">http://www.n8williams.com/devblog/?p=5</guid>
		<description><![CDATA[So after being confused as to why I kept seeing the javascript error &#8216;missing ; before statement&#8217;, I realized that javascript variables can&#8217;t begin with a number.
My code was:
for (int i = 0; i &#60; top; ++i) {
   eval("form." + fieldsArray[i] + ".value");
}

fieldsArray contains a string &#8216;0to99scans&#8217; referring to a form input &#8216;0to99scans&#8217;. [...]]]></description>
			<content:encoded><![CDATA[<p>So after being confused as to why I kept seeing the javascript error &#8216;missing ; before statement&#8217;, I realized that javascript variables can&#8217;t begin with a number.</p>
<p>My code was:</p>
<div class="text-box"><code>for (int i = 0; i &lt; top; ++i) {<br />
   eval("form." + <span style="color:red">fieldsArray[i]</span> + ".value");<br />
}</code>
</div>
<p>fieldsArray contains a string &#8216;0to99scans&#8217; referring to a form input &#8216;0to99scans&#8217;. This should have been something like &#8216;zeroTo499scans&#8217;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.n8williams.com/devblog/javascript_and_ajax/javascript-variable-names/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
