Re: JavaScript ajax library critique
- From: David Mark <dmark.cinsoft@xxxxxxxxx>
- Date: Wed, 23 Dec 2009 21:02:45 -0800 (PST)
On Dec 23, 10:38 pm, JR <groups_j...@xxxxxxxxxxxx> wrote:
On 23 dez, 20:06, David Mark <dmark.cins...@xxxxxxxxx> wrote:
On Dec 23, 4:47 pm, JR <groups_j...@xxxxxxxxxxxx> wrote:
On Dec 23, 7:07 pm, David Mark <dmark.cins...@xxxxxxxxx> wrote:
On Dec 23, 3:57 pm, JR <groups_j...@xxxxxxxxxxxx> wrote:
On Dec 23, 3:59 pm, Mychal Hackman <mycha...@xxxxxxxxx> wrote:
I have modified the code using information presented in this
discussion:
var Ajax = (function(){
var getXhr = (function(){
if(typeof window.XMLHttpRequest != 'undefined'){
return new XMLHttpRequest();
As (window.someThing) can return an object, null or undefined (on the
browser-side), it's irrelevant to check for 'typeof window.someThing'.
So,
if (typeof window.XMLHttpRequest != 'undefined') {}
is equivalent to just
if (window.XMLHttpRequest) {} // null, undefined and '' evaluate to
false.
Never detect host objects by type conversion. Some of them blow
up. :)
I can't remember a single case in which window.XMLHttpRequest or
window.ActiveXObject should 'blow up'. I'm sitting on a bomb and
didn't know about that (just kidding).
Do you keep a running list of host objects that do? It's best to
avoid the issue.
Wise advice. Thanks.
I suggest checking for that in the first place, because IE is *still*
the most used browser (I hat to admit that). For instance:
var getXhr = (function() {
var activeXmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
if (window.ActiveXObject) {
No. IE has supported XMLHttpRequest since version 7
Ok, I forgot that IE's native XMLHTTP support is enabled by default.
But anyone can disable it, so...
You need to use a try-catch with it as well.
Anyway, if even MS checks for the
native object as a first step, I won't be the 'smart alec' here saying
the contrary:
Huh?
http://msdn.microsoft.com/en-us/library/ms537505(VS.85).aspx
What is it you see there?
I see the following text [excerpt]:
"XMLHTTP in IE7 vs. IE6
The native implementation of the XMLHTTP object is designed with cross-
browser compatibility in mind. With just a bit of script, it is easy
to build a function that works with either version of Internet
Explorer, or any browser that supports XMLHTTP. See XMLHttpRequest for
complete documentation and examples.
var xmlHttp = null;
if (window.XMLHttpRequest) {
So, they don't know how to detect their own hosts' features.
// If IE7, Mozilla, Safari, and so on: Use native object.
xmlHttp = new XMLHttpRequest();}
else
{
if (window.ActiveXObject) {
And so on.
// ...otherwise, use the ActiveX control for IE5.x and IE6.
xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
No try-catch either. :)
}
}
Internet Explorer 7 supports the legacy implementation of XMLHTTP in
addition to the new native object, so pages currently using the
ActiveX control do not have to be rewritten. However, it is more
efficient to create a native scriptable object than to create an
ActiveX object. This is especially beneficial to those AJAX
applications that create a new XMLHTTP object for each request.
Yes. Lot of those. :(
The native object also supports the use of expandos (custom
properties), and properly recognizes the 'this' notation of
Javascript.
ActiveX vs. XMLHTTP
Users and organizations that choose to disallow ActiveX controls can
still use XMLHTTP-based Web applications in Internet Explorer 7.
Yes.
However, native XMLHTTP support can be disabled from the Advanced
settings tab of the Internet Options dialog box.
Yes.
[...]
If native XMLHTTP has been disabled, developers can override the
XMLHttpRequest property of the window object with the MSXML-XMLHTTP
control, unless ActiveX has also been disabled, as in the following
example.
if (!window.XMLHttpRequest) {
window.XMLHttpRequest = function() {
try {
return new ActiveXObject('MSXML2.XMLHTTP.3.0');
}
catch (ex) {
return null;
}
}}
Awful.
.
- Follow-Ups:
- Re: JavaScript ajax library critique
- From: Thomas 'PointedEars' Lahn
- Re: JavaScript ajax library critique
- References:
- JavaScript ajax library critique
- From: Mychal Hackman
- Re: JavaScript ajax library critique
- From: Garrett Smith
- Re: JavaScript ajax library critique
- From: Thomas 'PointedEars' Lahn
- Re: JavaScript ajax library critique
- From: David Mark
- Re: JavaScript ajax library critique
- From: Garrett Smith
- Re: JavaScript ajax library critique
- From: David Mark
- Re: JavaScript ajax library critique
- From: Mychal Hackman
- Re: JavaScript ajax library critique
- From: JR
- Re: JavaScript ajax library critique
- From: David Mark
- Re: JavaScript ajax library critique
- From: JR
- Re: JavaScript ajax library critique
- From: David Mark
- Re: JavaScript ajax library critique
- From: JR
- JavaScript ajax library critique
- Prev by Date: Re: Simple Ajax question.
- Next by Date: Re: Simple Ajax question.
- Previous by thread: Re: JavaScript ajax library critique
- Next by thread: Re: JavaScript ajax library critique
- Index(es):
Relevant Pages
|