The Dev Pages

A knowledge base for simple (and beyond) web applications development

Archive for the ‘Javascript and AJAX’ Category




So the autoOpen:false on the jQuery dialog instantiation doesn’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’t show up because the child divs have all inherited the display:none;

Just call the show method after the dialog load to skirt this.

$(”#detailPopin”).dialog(’open’);
$(”#detailPopin”).show();




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).

I added the following to the if on line 1948 – || !jQuery.event.special[type].teardown. This fixes the jQuery error on line 1948.

if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem)
=== false ) {

becomes

if ( !jQuery.event.special[type] || !jQuery.event.special[type].teardown
|| jQuery.event.special[type].teardown.call(elem) === false ) {

This makes it so if the teardown function is undefined, an error won’t occur.

I am fairly certain that this fix doesn’t break anything else, but no guarantees. I didn’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.




So if your using jQuery UI dialogs, you may run into issues with IE 7. Apparently the value of a usually ‘undefined’ javascript variable can get set to ‘NaNpx’ 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: “Line: 1102 Error: invalid argument.”

This error comes from code around line 1101 in jquery-1-2-6.js.

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 – that code looks more like the most recent release of jQuery).

/* MODIFIED 7/31/08 BY NATE
* WAS THIS, but IE7 was throwing an error
if ( value != undefined )
elem[ name ] = value;
*/
if ( value != 'NaNpx' && value != undefined)
elem[ name ] = value; //NATE - Sometimes the value would come up as NaNpx in
IE and causes an error

jquery runtime error for dialog




If you try and set the style attribute of a DOM element with Javascript, the following code WON’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/




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/




You’re trying to get the substring of a number, or something else, maybe undefined.

trimAll(document.getElementById(”email”).value.length)

should be

trimAll(document.getElementById(”email”)).value.length




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 “Permission Denied to call method yourXMLHttpRequestObject.open” Errors! But only in IE.

In IE, with AJAX requests, your url root must match your base href. base ref=”http://www.mydomain.com should be the same as the base url in xmlHttp.open(”GET”, “http://www.mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?
method=getOrderInfoXML&userid=1234″, true), or you can use relative urls.

Example I had:

//The XMLHttpRequest is named xmlHttp here, xmlHttp = new XMLHttpRequest()
//If the base href is set to something other than the server root, the AJAX request
//thinks the request is coming from a different server, or something.
//Permission denied to call XMLHttp.open with the following
//SET IN HTML HEAD <base href="http://www.mydomain.com/index.cfm?event=myOrder" /> - NOT HTTPS!
xmlHttp.open("GET", "https://mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?
method=getOrderInfoXML&userid=1234" , true);

//Now when the base href is set to the server root, no problems
//SET IN HTML HEAD <base href="https://www.mydomain.com/"> - HTTP!
xmlHttp.open("GET", "https://mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?
method=getOrderInfoXML&userid=1234" , true);

Issues when www isn’t mapped to your home url

Another issue that can happen with access denied errors with your AJAX request is when your www doesn’t resolve to the same url as your root. I.E. http://www.yourdomain.com isn’t the same dns entry as http://ourdomain.com, even if they both eventually go to the same server ip.

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’t resolve to http://yourdomain.com).

//I'm on a http:://www.mydomain.com page, and I get an error with this line
xmlHttp.open("GET", "http://mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?
method=getOrderInfoXML&userid=1234" , true);
// I'm on a http:://mydomain.com page, this line will work
xmlHttp.open("GET", "http://mydomain.com/MyRemoteServices/MyRemoteOrderService.cfc?
method=getOrderInfoXML&userid=1234" , true);



So after being confused as to why I kept seeing the javascript error ‘missing ; before statement’, I realized that javascript variables can’t begin with a number.

My code was:

for (int i = 0; i < top; ++i) {
eval("form." + fieldsArray[i] + ".value");
}

fieldsArray contains a string ‘0to99scans’ referring to a form input ‘0to99scans’. This should have been something like ‘zeroTo499scans’.