Re: JavaScript ajax library critique



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) {
// If IE7, Mozilla, Safari, and so on: Use native object.
xmlHttp = new XMLHttpRequest();
}
else
{
if (window.ActiveXObject) {
// ...otherwise, use the ActiveX control for IE5.x and IE6.
xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
}
}

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.

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.
However, native XMLHTTP support can be disabled from the Advanced
settings tab of the Internet Options dialog box.

Internet Options Dialog
Clients can configure their own policy and simultaneously retain
functionality across key AJAX scenarios. By default, the native
implementation of XMLHTTP is enabled for all MSHTML hosts; however,
individual host applications can choose to disable XMLHTTP with the
FEATURE_XMLHTTP feature control key. An organization can use Group
Policy to disable XMLHTTP for all users of its network.

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;
}
}
}
"


[...] some users have
ActiveX disabled for them and some agents have dummy global
ActiveXObject properties to prevent unnecessary exclusion by browser
sniffing scripts.

I didn't follow what's the problem?

Some agents implement window.ActiveXObject, but it doesn't do anything.

Thanks for that!

Cheers,
JR
.



Relevant Pages

  • Re: XMLHttpRequest on CE
    ... Is the browser that you're using to connect to the secure site on the WinCE ... XMLHttp because the issuer of the server cert is not in the CE device's ... > http post to a remote web service using an MSXML XMLHttpRequest object. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: JavaScript ajax library critique
    ... the most used browser. ... native object as a first step, I won't be the 'smart alec' here saying ... "XMLHTTP in IE7 vs. IE6 ... ActiveX control do not have to be rewritten. ...
    (comp.lang.javascript)
  • Re: AJAX, JS and scoping
    ... call-back function it's complaining that xmlHttp doesn't exist when I try to ... var xmlHttp = AjaxRequest; ... Lastly, I guess, you might want to split up your libraries to be browser ...
    (Fedora)
  • Re: AJAX Style processing icon
    ... process I'm running in the background with xmlHttp is intensive and ... Instead of my processing icon ... var url="getIndustries.aspx" ... It will make less work for the browser. ...
    (comp.lang.javascript)
  • Re: ActiveX plugin in Safari in Mac
    ... option is written as an activex browser plugin. ... works fine in IE on windows OS. ... I'm not even sure it is supported in any browser except ... Internet Explorer. ...
    (comp.sys.mac.system)