JavaScript ajax library critique

T

Thomas 'PointedEars' Lahn

Garrett said:
Thomas said:
Garrett said:
Hans-Georg Michna wrote:
On Thu, 31 Dec 2009 14:07:37 -0800, Garrett Smith wrote:
The problem with adding a user-defiend global XMLHttpRequest is that
it will trip up other code that makes the same check:-

if(typeof XMLHttpRequest == "undefined") {

}
It makes your user-defined function look like the real deal.

And that is bad[tm], because ...?

Making the user-defined function look like the real deal is bad because
it isn't.
Nonsense.

If a script makes a check:-

var IS_NATIVE_XHR = typeof XMLHttpRequest !== "undefined";

- the script is misled. It might seem safe, but it isn't; the
user-defined new XMLHttpRequest() can throw:-

"This browser does not support XMLHttpRequest."

And that is bad[tm], because ...? If it CAN `throw' (there is no MUST),
scripts using it can (and should) `try'...`catch'.


PointedEars
 
T

Thomas 'PointedEars' Lahn

JR said:
According to MSDN (http://msdn.microsoft.com/en-us/library/
cc507441%28VS.85%29.aspx)
- "MSXML 3.0 and prior versions of MSXML are version independent.
MSXML 3.0 was the last version of MSXML to support version-independent
CLSIDs and ProgIDs."

So what?
- "MSXML 3.0 is supported in Windows Vista; Windows Server 2003;
Windows XP; Windows 2000; Windows 98; Windows Millenium Edition (ME)."

So what?
You seem to be mistaking MSXML versions with IE versions.

No, I don't. Curious how you got that idea again.
You may look
for msxml3.dll (v. 3.0) in your Windows\System32 folder to verify the
above information.

This information is irrelevant to the discussed problem.
Since the OP's original code 'try-catch' only version 2.0
(Microsoft.XMLHTTP), I think his code needs to test for version 3.0 as
well (MSXML2.XMLHTTP).

What for, if "Microsoft.XMLHTTP" is apparently both upwards and downwards-
compatible (running on Vista with msxml3.dll to msxml6.dll, and Windows XP
with msxml3.dll only, but no msxml2.dll or msxml1.dll here)?

And suppose the advantage is bugfixes in the greater versions, why not
prefer all the greater versions to get the latest bugfixes?

Your argument can be turned up and down, it simply does not make any sense.


PointedEars
 
J

JR

So what?


So what?


No, I don't.  Curious how you got that idea again.


This information is irrelevant to the discussed problem.


What for, if "Microsoft.XMLHTTP" is apparently both upwards and downwards-
compatible (running on Vista with msxml3.dll to msxml6.dll, and Windows XP
with msxml3.dll only, but no msxml2.dll or msxml1.dll here)?

And suppose the advantage is bugfixes in the greater versions, why not
prefer all the greater versions to get the latest bugfixes?

Your argument can be turned up and down, it simply does not make any sense.

No, the argument is clear for those who pay minimum attention while
reading.

JR
 
T

Thomas 'PointedEars' Lahn

JR said:
No, the argument is clear for those who pay minimum attention while
reading.

Is that so? Then, pray tell, what exactly is the advantage of
trying "Msxml2.XMLHTTP" before or instead of "Microsoft.XMLHTTP"?


PointedEars
 
J

JR

Perhaps not all of them. Microsoft recommends not to use
versions 4 and 5. They say, check for 6.0. If that is not there,
use 3.0.

I've found an article on MSDN stating exactly the same. Furthermore,
there's another article on MSDN that doesn't encourage using version
5, which is installed by Office 2003. Inspecting my computer which has
Office 2003, I've confirmed that msxml5.dll is located in:
"C:\Program files\Common files\Microsoft Shared\OFFICE11\MSXML5.DLL"
All earlier versions are for IE versions before 6.

Nowadays, it might be odd to find IE 5 or 5.5 on an XP or Vista
installation. But, in that case, I suppose IE 5 could instantiate
versions 3 and 6, because both XP and Vista come with the mentioned
versions of MSXML. But I can't test this supposition.

After searching my Windows Vista registry for "Msxml2.XMLHTTP", I've
found out two CLSID keys: one related to the "msxml2.dll" (version 2.6
on my system) and the other related to the "msxml3.dll" (version 3.0).
This is consistent with the MSDN article "MSXML 3.0 GUIDs and
ProgIDs" (http://msdn.microsoft.com/en-us/library/ms766426(VS.
85%29.aspx).

But searching further, I've noticed that both "Microsoft.XMLHTTP" and
"Microsoft.XMLHTTP.1.0" are related to the msxml3.dll too. What? Now
it's not consistent with the same article on MSDN.

I've used VBA to instantiating "Msxml2.XMLHTTP", but I couldn't find
any property informing the dll filename or XMLHTTP version. I think
I'd need some C++ code to inspect what is really going on...

In short, after studying this matter I think the best approach would
be (referring to the OP's example):

var ajax = {
transport : (function () {
var req = null;
if (typeof window.XMLHttpRequest != "undefined") {
// IE7+, FF, Opera 8.0+, Safari.
try { req = new XMLHttpRequest(); }
catch (ex1) { } // Ignores.
} else if (typeof window.ActiveXObject != "undefined") {
//IE 5+, 6, or IE7/8 with native XMLHTTP support disabled.
try { req = new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
catch (ex2) {
try { req = new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
catch (ex3) {
try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (ex4) { } // game over.
}
}
} else {
// alert("Your browser doesn't support AJAX. Sorry!");
}
return req;
})(),

// other properties.

};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top