Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Using XMLHttpRequest run locally for local data reading

Reply
Thread Tools

Using XMLHttpRequest run locally for local data reading

 
 
VK
Guest
Posts: n/a
 
      04-24-2010
In continuation of http://groups.google.com/group/comp....7389d10afcaf77

Test (unzip and run AJAX/test/index.html):
http://sites.google.com/site/schoolsring/javascript
LocalDataReadingTest.zip


In each test:
1) attempt to read xml file in the same directory
2) attempt to read xml file in subdirectory
3) attempt to read xml file in top directory
4) attempt to read xml file in sibling directory

Each reading made twice: one time with without overriding MIME type,
next time with implied "text/xml" type.


1) IE
Internet Explorer 8.0 / Windows Vista SP2 - newest
Internet Explorer 6.0.2900 / Windows XP SP2 - legacy test

window.XMLHttpRequest in new IE does NOT allow local data reading at
all.

window.ActiveXObject(ProgID) doesn't support .overrideMimeType method

Without implied "text/xml" Content-type the results are:

OK attempt to read xml file in the same directory
OK attempt to read xml file in subdirectory
OK attempt to read xml file in top directory
OK attempt to read xml file in sibling directory

success request status = 0

.requestXML is empty, a manual serialization from responseText is
needed later.


2) Fx
Mozilla Firefox 3.6.3 / Windows Vista SP2 - newest
Mozilla Firefox 3.5.7 / Windows XP SP2 - legacy test

OK attempt to read xml file in the same directory
OK attempt to read xml file in subdirectory
_ attempt to read xml file in top directory (Error: Access to
restricted URI denied)
_ attempt to read xml file in sibling directory (Error: Access to
restricted URI denied)

success request status = 0

.requestXML is filled properly either with or without
using .overrideMimeType method


3) Sf
Apple Safari 4.0.5 / Windows Vista SP2

OK attempt to read xml file in the same directory
OK attempt to read xml file in subdirectory
OK attempt to read xml file in top directory
OK attempt to read xml file in sibling directory

success request status = 0

.requestXML is filled properly either with or without
using .overrideMimeType method


4) Ch
Google Chrome 4.1.249 / Windows Vista SP2

OK attempt to read xml file in the same directory
OK attempt to read xml file in subdirectory
OK attempt to read xml file in top directory
OK attempt to read xml file in sibling directory

success request status = 0

.requestXML is filled properly either with or without
using .overrideMimeType method


5) Op
Opera 10.51 / Windows Vista SP2

OK attempt to read xml file in the same directory
OK attempt to read xml file in subdirectory
OK attempt to read xml file in top directory
OK attempt to read xml file in sibling directory

success request status = 0

.requestXML is filled properly either with or without
using .overrideMimeType method


Conclusions:
1) IE sucks but usable
2) Fx is the most strict
3) overrideMimeType is useless: it is not needed where supported
and it is not supported where needed

4) The quality of XMLHttpRequest instantiation blocks in all
prominent libraries is *awful*... No, sorry: it is AWFUL. No... It is
a BLOODY AWFUL NIGHTMARE. The guys didn't read MSDN for years. If they
don't care about IE users whatsoever is fine, but they should
explicitly mark it then. I am posting the XHR init part from the test
file here - not as a sample of an outstanding coding, but at least to
show some descent approach with the crucial points commented:


function getAjaxObject(forLocalData) {

var isIE = /*@cc_on/*@if(@_jscript)true@else@*/false/*@end@*/;

var xhr = null;

if (typeof window == 'object') {

/* Common branch for modern browsers */
if (
(typeof window.XMLHttpRequest != 'undefined') &&
// window.XMLHttpRequest instances in IE do not
// have local file access even from local pages,
// unlike ActiveX instances: so if forLocalData
// flag set, we are trying to use the underlaying
// ActiveX constructor.
!(isIE && forLocalData)
) {
try {
return new window.XMLHttpRequest();
}
catch(e) {
return new Error(e.message);
}
}

/* ActiveX branch for old IE versions and for local data access
capable instances, see:
* http://blogs.msdn.com/xmlteam/archiv...-explorer.aspx
* http://groups.google.com/group/micro...d173be4950e107
* http://blogs.msdn.com/ie/archive/2006/01/23/516393.aspx
* for proper ProgID and proper ProgID trying sequence.
*/
else if (
(isIE) &&
(typeof window.ActiveXObject != 'undefined') // IE 5.x for MacOS
without ActiveX
) {
try {
return new window.ActiveXObject('Msxml2.XMLHTTP.6.0');
}
catch(e) {
try {
xhr = new window.ActiveXObject('Msxml2.XMLHTTP.3.0');
/* Msxml2.XMLHTTP.3.0 and older have XSL Patterns as the
* defailt XML language, not XPath, so fixing it:
*/
xhr.setProperty('SelectionLanguage', 'XPath');
return xhr;
}
catch(e) {
try {
xhr = new window.ActiveXObject('Msxml2.XMLHTTP');
/* Msxml2.XMLHTTP (IE6 / Win XP SP2 in default installation)
* have XSL Patterns as the defailt XML language, not XPath,
* but it doesn't support .setProperty switch.
* Setting the warning flag at the very least:
*/
arguments.callee.isXSLPatterns = true;
return xhr;
}
catch(e) {
/* Microsoft.XMLHTTP ProgID as the last ressort is not used
* as the security consideration should prevail over the
* maximum backward compatibility. Unlock for special cases only.
*/
//try {
// return new window.ActiveXObject('Microsoft.XMLHTTP');
//}
//catch(e) {
// return new Error(e.message);
//}
return new Error(e.message);
}
}
}
}

/* If nothing then nothing... */
else {
return new Error('ActiveX is missing or blocked');
}
}
else {
return new Error('window host object is missing');
}
}
 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      04-24-2010
On Apr 24, 8:40*pm, VK <schools_r...@yahoo.com> wrote:
> Conclusions:
> *1) IE sucks but usable
> *2) Fx is the most strict


....

5) async request checked for "200 OK" status only means either of two
things:
a) the coder has no clue about Ajax he/she dared to program
b) the coder deliberately decided to make his Ajax not usable for
local data
reading but failed to inform his/her users.

All good boys and girls (the one who reading c.l.j. always do like
this:

if ((myRequest.status == 200) || (myRequest.status == 0)) {
// success
}


6) XHR instantiation w/o explicit IE check and w/o possibility to flag
for ActiveX instead of XMLHttpRequest is a strong sign of i) a
clueless coding or ii) 5-b above
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-24-2010
VK wrote:

> [...] I am posting the XHR init part from the test file here - not as a
> sample of an outstanding coding,


What else is new?

> but at least to show some descent approach with the crucial points
> commented:


In your fantasy world, perhaps.

> function getAjaxObject(forLocalData) {
>
> var isIE = /*@cc_on/*@if(@_jscript)true@else@*/false/*@end@*/;


OMG.

> var xhr = null;
>
> if (typeof window == 'object') {
>
> /* Common branch for modern browsers */
> if (
> (typeof window.XMLHttpRequest != 'undefined') &&
> [...]
> !(isIE && forLocalData)
> ) {
> [...]
> }
> [...]
> else if (
> (isIE) &&
> (typeof window.ActiveXObject != 'undefined') // IE 5.x for MacOS
> without ActiveX
> ) {


Apparently you are not paying attention.

> try {
> return new window.ActiveXObject('Msxml2.XMLHTTP.6.0');
> }
> catch(e) {
> try {
> xhr = new window.ActiveXObject('Msxml2.XMLHTTP.3.0');
> [aso.]


Obviously you are not paying attention at all, or your puny mind is unable
to process or store the discussion results.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      04-24-2010
On Apr 24, 11:08*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:

> > *var isIE = /*@cc_on/*@if(@_jscript)true@else@*/false/*@end@*/;


Thomas, it is from a real production code, not usual c.l.j. child
games. It takes more efforts to comprehend, but the results are
fruitful. It is a JScript conditional compilation statement:
http://msdn.microsoft.com/en-us/libr...t1(VS.80).aspx
Any browser but IE will see false, IE will see true.

Why not the regular baby check
if (window.ActiveXObject) { ...
?

Because baby checks need baby efforts to spoof, like
if !!(window.ActiveXObject) {
window.ActiveXObject = new OurAjaxLoophole();
}


> > *var xhr = null;

>
> > *if (typeof window == 'object') {

>
> > /* Common branch for modern browsers */
> > * if (
> > * * (typeof window.XMLHttpRequest != 'undefined') &&
> > [...]
> > * * !(isIE && forLocalData)
> > * *) {
> > [...]
> > * }
> > [...]
> > * else if (
> > * * (isIE) &&
> > * * (typeof window.ActiveXObject != 'undefined') // IE 5.x for MacOS
> > without ActiveX
> > * *) {

>
> Apparently you are not paying attention.
> > * *try {
> > * * return new window.ActiveXObject('Msxml2.XMLHTTP.6.0');
> > * *}
> > * *catch(e) {
> > * * try {
> > * * *xhr = new window.ActiveXObject('Msxml2.XMLHTTP.3.0');
> > [aso.]

>
> Obviously you are not paying attention at all, or your puny mind is unable
> to process or store the discussion results.


No, it is just might be hard to realize how little one (you) know
about the real compatibility. The link to resources are provided right
and the code, read and learn. A separate hint as it is the most
popular urban legend about XHR on IE:
No, ActiveXObject('Msxml2.XMLHTTP') does NOT mean "take the latest/
current version". It means: "take the oldest one from all available".
For the rest keep study linked resources. Do not hesitate to ask for
explanations or for extra test cases for particular points.

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-24-2010
VK wrote:

> Thomas 'PointedEars' Lahn wrote:
>> > var isIE = /*@cc_on/*@if(@_jscript)true@else@*/false/*@end@*/;

>
> Thomas, it is from a real production code,


I pity your users already.

> not usual c.l.j. child games.


It's your usual nonsense. JScript support has *nothing* to do with the
underlying DOM that provides the `XMLHttpRequest' and `ActiveXObject'
objects.

> [...] It takes more efforts to comprehend,


One must be smoking what you are smoking to "comprehend" that.

> but the results are fruitful.


Hardly.

> It is a JScript conditional compilation statement:
> http://msdn.microsoft.com/en-us/libr...t1(VS.80).aspx


I *know* what it is, stupid.

> Any browser but IE will see false, [...]


Definitely no.

> Why not the regular baby check
> if (window.ActiveXObject) { ...
> ?


Nobody but you here recommends that, stupid.

> Because baby checks need baby efforts to spoof, like
> if !!(window.ActiveXObject) {
> window.ActiveXObject = new OurAjaxLoophole();
> }


That's not even syntactically valid.

>> > var xhr = null;

>>
>> > if (typeof window == 'object') {

>>
>> > /* Common branch for modern browsers */
>> > if (
>> > (typeof window.XMLHttpRequest != 'undefined') &&
>> > [...]
>> > !(isIE && forLocalData)
>> > ) {
>> > [...]
>> > }
>> > [...]
>> > else if (
>> > (isIE) &&
>> > (typeof window.ActiveXObject != 'undefined') // IE 5.x for MacOS
>> > without ActiveX
>> > ) {

>>
>> Apparently you are not paying attention.
>> > try {
>> > return new window.ActiveXObject('Msxml2.XMLHTTP.6.0');
>> > }
>> > catch(e) {
>> > try {
>> > xhr = new window.ActiveXObject('Msxml2.XMLHTTP.3.0');
>> > [aso.]

>>
>> Obviously you are not paying attention at all, or your puny mind is
>> unable to process or store the discussion results.

>
> No, it is just might be hard to realize how little one (you) know
> about the real compatibility. [...]


Often Wrong, your code will _not_ work in MSHTML with local files to begin
with.


PointedEarws
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$> (2004)
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      04-24-2010
On Apr 24, 11:33*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
> JScript support has *nothing* to do with the
> underlying DOM that provides the `XMLHttpRequest' and `ActiveXObject'
> objects.


Real production has *nothing* to do with theoretical masturbations.
ActiveXObject = IE. IE = ActiveXObject. For the rest - write poems on
c.l.j. Someone may read them.

> > It is a JScript conditional compilation statement:
> > *http://msdn.microsoft.com/en-us/libr...t1(VS.80).aspx

>
> I *know* what it is, stupid.


That's good for a starter.

> > Any browser but IE will see false, [...]

>
> Definitely no.


Definitely yes, silly boy. You just claimed you knew the matter.


> Often Wrong, your code will _not_ work in MSHTML with local files to begin
> with.


OK, PointedEars, I am ready to have a harsh or not so harsh
*discussion* but I will not respond to a pure blind trolling. The test
results were received using this code, the code is posted as one zip
file to download. Get it and check it. If you want to call me a liar
who fabricates *results* (leaving out their interpretations for now) -
then you better do not do it.



 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-24-2010
VK wrote:

> Thomas 'PointedEars' Lahn wrote:
>> JScript support has *nothing* to do with the
>> underlying DOM that provides the `XMLHttpRequest' and `ActiveXObject'
>> objects.

>
> Real production has *nothing* to do with theoretical masturbations.
> ActiveXObject = IE. IE = ActiveXObject. For the rest - write poems on
> c.l.j. Someone may read them.


You're such an idiot:

<http://en.wikipedia.org/wiki/MSHTML#Trident-based_applications>


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$> (2004)
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      04-24-2010
On Apr 24, 11:52*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
> VK wrote:
> > Thomas 'PointedEars' Lahn wrote:
> >> JScript support has *nothing* to do with the
> >> underlying DOM that provides the `XMLHttpRequest' and `ActiveXObject'
> >> objects.

>
> > Real production has *nothing* to do with theoretical masturbations.
> > ActiveXObject = IE. IE = ActiveXObject. For the rest - write poems on
> > c.l.j. Someone may read them.

>
> You're such an idiot:
>
> <http://en.wikipedia.org/wiki/MSHTML#Trident-based_applications>


You are so silly. What connection in your mind is between a rendering
engine .dll and COM / ActiveX? A hint: none, except the substrings
"MS" and "HTML" one can find both in .dll name and in some ProgIDs

Learn, learn, learn - that's the only salvation. At the spare time try
to use new ActiveXObject(whatever) in Winamp, it does use Trident as
well
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-24-2010
VK wrote:

> Thomas 'PointedEars' Lahn wrote:
>> VK wrote:
>> > Thomas 'PointedEars' Lahn wrote:
>> >> JScript support has *nothing* to do with the
>> >> underlying DOM that provides the `XMLHttpRequest' and `ActiveXObject'
>> >> objects.

>>
>> > Real production has *nothing* to do with theoretical masturbations.
>> > ActiveXObject = IE. IE = ActiveXObject. For the rest - write poems on
>> > c.l.j. Someone may read them.

>>
>> You're such an idiot:
>>
>> <http://en.wikipedia.org/wiki/MSHTML#Trident-based_applications>

>
> You are so silly. What connection in your mind is between a rendering
> engine .dll and COM / ActiveX? A hint: none, [rubbish recycled]


The layout engine usually provides the host environment for DOM objects. It
is true that MSHTML does not need to mean ActiveX is also supported.
However, more important is that there is not a necessary connection between
_layout_ engine and the DOM binding it provides and the supported scripting
language. That is why your approach is junk.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$>
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      04-24-2010
On Apr 25, 12:24*am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
> The layout engine usually provides the host environment for DOM objects.


Uhmm... It is a very simplistic way to put it, but OK.

> It is true that MSHTML does not need to mean ActiveX is also supported.
> However, more important is that there is not a necessary connection between
> _layout_ engine and the DOM binding it provides and the supported scripting
> language.


For IE of any version COM interfaces, accessible over
window.ActiveXObject, are not part of a rendering engine nor even part
of IE itself. They are programmed into JScript engine. And JScript
engine in IE of any version is one separate DLL library located at
%SystemRoot%System32/jscript.dll
It is made so because jscript.dll is not a part of IE, it is a system
dll needed for Windows Script Host functionality in its JScript part.
The other system dll %SystemRoot%System32/vbscript.dll provides WSH
VBScript part of functionality. So either one has IE installed or not,
these dll are there, unless the system is badly broken. But IE
installations may upgrade these dll to newer ones if instructed to do
so. So IE is just yet another user of jscript.dll. Moreover until IE7
it was possible to replace jscript.dll so making IE6 running with
JScript for IE5 or IE5 running with JScript for IE6. Funny, but
crashes quickly.

Any way, to make the long story shorter:
var isIE = /*@cc_on/*@if(@_jscript)true@else@*/false/*@end@*/;
effectively checks if the environment uses jscript.dll so running
Microsoft JScript of some (easy to check) version. If false, than it
is not Microsoft JScript, that is not jscript.dll and no way in the
world - atop of all other consequences - it may implement Microsoft
ActiveXObject. I am obviously talking about officially released
commercial software.

> That is why your approach is junk.


This is why my approach is bulletproof and ActiveXObject feature
testing is junk.

P.S. As a side note I am a bit suspicious about IE-compatibility
experts claiming that they never had and/or not having any Microsoft
products and being happy with *nux or MacOS. This one not directly to
you, just an observation. Where do they get all their M$-related
wisdom? From their "mis-fortunate" M$'ed friends? As a sample of the
prevailing illiteracy on Msxml2.XMLHTTP topic this W3Schools "valuable
advise" at
http://www.w3schools.com/xpath/xpath_examples.asp
"To solve the [0] and [1] problem in IE5+, you can set the
SelectionLanguage to XPath."
Splendid! "This property or method is not supported" runtime error for
all IE users up to IE7, unless they manually updated their XMLHTTP
libraries.
About their XHR instantiation approach I have nothing to say at all:
http://www.w3schools.com/ajax/ajax_x...est_create.asp
Whoever read comments in the code I posted will easily understand that
W3Schools is NOT a place to learn, at least about Ajax.
But hell with W3Schools - lousy were, lousy stay, lousy will remain.
The whole Web info like that on the topic, and respectively all libs
like that. "X said to Y that Z heard from... that..." And that's past
over 5 years after the "Ajax" explosion! http://www.adaptivepath.com/ideas/es...ves/000385.php
What is wrong with the world?..


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reading php-mysql data through xmlhttprequest foraci@gmail.com Javascript 0 01-11-2007 09:01 AM
reading php/mysql data through xmlhttprequest fool Javascript 0 01-08-2007 04:07 PM
How run web software *locally* easily? seberino@spawar.navy.mil Python 3 01-06-2006 10:05 AM
Java applets run locally now blocked by Windows XP SP2 Mickey Segal Java 9 01-08-2005 10:40 PM
Store ASP.NET project files remotely, run project locally? Raterus ASP .Net 2 04-28-2004 03:30 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57