Prev: Quicktime and innerHTML
Next: option & textnode
From: Thomas 'PointedEars' Lahn on 22 Apr 2010 13:14 foka wrote: > [Stefan Weiss wrote:] >> I assume that you've declared the xmlDoc variable somewhere else. >> >> Which browser are you using, and what exactly does loadXMLDoc do (except >> that it "reads data", if I translated the comment correctly)? > > I used every browser. IE8, Chrome, Firefox. OMG. That is "every browser" for you? > Everything is ok if I run my site on serwer( I have wamp server on > Windows to test) No, not really. >> Did this line trigger an error? If not, did you enable error reporting >> in your browser? If there really is no error, how come you get a valid >> XML document that is somehow missing its <group> tags? >> >> By the way, you may want use an asynchronous XMLHttpRequest. > > I'm beginner. So not exactly in a position to say for sure that ... > There is no errors. XML file is correct. Doubtful, given ... > My whole test.html site: > > <?xml version="1.0" encoding="UTF-8"?> This triggers Compatibility Mode when served as text/html, and XML mode when served as */xml. YAGNI. > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl"> > [...] > <script type="text/javascript" language="javascript"> ^^^^^^^^ Not Valid. > [...] > if (window.XMLHttpRequest) if (typeof XMLHttpRequest != undefined) (for a start, see isMethod() for more) > xhttp=new XMLHttpRequest(); Where do you declare this? > xhttp=new ActiveXObject("Microsoft.XMLHTTP"); You do need to catch exceptions this may throw. > xhttp.open("GET",dname,false); > xhttp.send(""); Use xhttp.open("GET", dname, true); xhttp.onreadystatechange = function (x) { // ... }; x.send(null); as suggested. At least don't pass "". > xmlDoc=loadXMLDoc(url_file); Where do you declare this? > for (var i=0; i < groupXml.length; i++) { -----------------------------------^ Syntax error, not well-formed. <http://validator.w3.org/> > document.forms['searchForm'].groups.options[i] = > new > Option(groupXml[i].firstChild.nodeValue,groupXml[i].firstChild.nodeValue); That's a *bit* inefficient. BTW, Internet Explorer does not support XHTML. Please leave an attribution line for each included quotation level. PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee
From: Thomas 'PointedEars' Lahn on 22 Apr 2010 13:21 Thomas 'PointedEars' Lahn wrote: > foka wrote: >> [...] >> if (window.XMLHttpRequest) > > if (typeof XMLHttpRequest != undefined) if (typeof XMLHttpRequest != "undefined") > (for a start, see isMethod() for more) But for local files (file://) you must prefer ActiveXObject() as XMLHttpRequest(), if supported, does not support file:// in MSHTML. PointedEars
From: foka on 22 Apr 2010 13:28 > Use > > xhttp.open("GET", dname, true); > xhttp.onreadystatechange = function (x) { > // ... > }; > x.send(null); > > as suggested. At least don't pass "". > >> xmlDoc=loadXMLDoc(url_file); I found this here: from http://www.w3schools.com/xml/xml_parser.asp if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else // Internet Explorer 5/6 { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET","books.xml",false); xhttp.send(""); xmlDoc=xhttp.responseXML; foka
From: VK on 22 Apr 2010 13:42 On Apr 22, 8:50 pm, foka <crazys...(a)onet.eu> wrote: > My javascript function: > > function loadXMLDoc(dname) > { > if (window.XMLHttpRequest) > { > xhttp=new XMLHttpRequest(); > } > else > { > xhttp=new ActiveXObject("Microsoft.XMLHTTP"); > } > xhttp.open("GET",dname,false); > xhttp.send(""); > return xhttp.responseXML; > > } > > What u suggest to correct? What and where to add? Nothing really. I just recalled another oops for local files: responseXML gets triggered and filled only if XML data is served with the proper Content-Type like "text/xml", otherwise responseXML remains empty. As you cannot send Content-Type for local file, you get no data into responseXML. Read responseText instead - your data is in there, but as text/plain of course. I do recall some enforceContentType or something for request, but honestly I would just take a time verified AJAX library rather that reinventing the wheel and hitting all per browser and per situation bizarrities.
From: Thomas 'PointedEars' Lahn on 22 Apr 2010 13:43
foka wrote: > [Thomas 'PointedEars' Lahn wrote:] > > Use > > > > xhttp.open("GET", dname, true); > > xhttp.onreadystatechange = function (x) { > > // ... > > }; > > x.send(null); > > > > as suggested. At least don't pass "". > > I found this here: from http://www.w3schools.com/xml/xml_parser.asp Now you have learned something. Please do not remove the attribution lines. PointedEars -- realism: HTML 4.01 Strict evangelism: XHTML 1.0 Strict madness: XHTML 1.1 as application/xhtml+xml -- Bjoern Hoehrmann |