Prev: Young girls showing off their bodies on personal webcams
Next: FAQ Topic - How do I change print settings for window.print()? (2010-04-25)
From: VK on 24 Apr 2010 12:40 In continuation of http://groups.google.com/group/comp.lang.javascript/msg/787389d10afcaf77 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(a)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/archive/2006/10/23/using-the-right-version-of-msxml-in-internet-explorer.aspx * http://groups.google.com/group/microsoft.public.xml/browse_frm/thread/7772ac2ad016e2bf/5bd173be4950e107 * 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'); } }
From: VK on 24 Apr 2010 14:26 On Apr 24, 8:40 pm, VK <schools_r...(a)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
From: Thomas 'PointedEars' Lahn on 24 Apr 2010 15:08 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(a)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.)
From: VK on 24 Apr 2010 15:25 On Apr 24, 11:08 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote: > > var isIE = /*@cc_on/*@if(@_jscript)true(a)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/library/7kx09ct1(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.
From: Thomas 'PointedEars' Lahn on 24 Apr 2010 15:33
VK wrote: > Thomas 'PointedEars' Lahn wrote: >> > var isIE = /*@cc_on/*@if(@_jscript)true(a)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/library/7kx09ct1(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$8300dec7(a)news.demon.co.uk> (2004) |