Re: JavaScript ajax library critique



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.

.



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. ... "XMLHTTP in IE7 vs. IE6 ... to build a function that works with either version of Internet ... 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)
  • xmlhttp req without ActiveX on IE 5/6
    ... Opera and IE 6 with ActiveX enabled ... "In IE6 and below, XMLHTTP is implemented as an ActiveX ... equivalent of an XMLHTTP object using IE 6 with ActiveX ...
    (comp.lang.javascript)