chelnov63 Posted September 23, 2009 Share Posted September 23, 2009 Really head scratcher this one... appreciate any help I have two drop down boxes, when someone selects an option from dropdown A - the associated xml file for that option is loaded in and populates dropdown B. All works fine except for ONE thing. When the assocaited XML file is just a regular .xml file everything works fine. However when it is a dynamically generated XML file the functionality just breaks down and the second dropdown is not populated - even though the end result XML is the same.. here is the relevant code where the update of the second combo box is triggered: function updateCombo(value) { loadSpecXMLDoc(value+".xml"); //IF I LOAD IT THIS WAY EVEYTHING WORKS FINE //loadSpecXMLDoc("http://staging.abc.co.uk/abc/abc.jsp?func=styles&model=value"); //THIS DYNAMIC WAY DOESNT WORK } function loadSpecXMLDoc(url) { xmlhttpspec=GetXmlHttpObject(); if (xmlhttpspec==null) { alert ("Your browser does not support XMLHTTP!"); return; } xmlhttpspec.onreadystatechange=specChanged; xmlhttpspec.open("GET",url,true); xmlhttpspec.send(null); } function specChanged() { if (xmlhttpspec.readyState==4) { if (xmlhttpspec.status==200) { alert(xmlhttpspec.responseText); // THIS ALWAYS SHOWS THE SAME RESULT //WITH DYNAMIC XML IT SEEMS TO BREAK DOWN HERE xmlSpecDoc = xmlhttpspec.responseXML.documentElement; //AS WITH DYNAMIC XML EVEN THIS ALERT IS NOT SHOWN alert("hello"); } else { alert("Problem retrieving XML data:" + xmlhttp.statusText); } } } So it seems to break down at the line xmlSpecDoc = xmlhttpspec.responseXML.documentElement; with dynamically generated XML ... is it possible that the response being sent back although it looks like XML is NOT XML but a string or something? I dont have access to that file.. any ideas would really help..thanks Quote Link to comment https://forums.phpfreaks.com/topic/175204-very-strange-problem-dynamically-generated-xml-not-working/ Share on other sites More sharing options...
RichardRotterdam Posted September 23, 2009 Share Posted September 23, 2009 In your code I see the following: loadSpecXMLDoc(value+".xml"); //IF I LOAD IT THIS WAY EVEYTHING WORKS FINE //loadSpecXMLDoc("http://staging.abc.co.uk/abc/abc.jsp?func=styles&model=value"); //THIS DYNAMIC WAY DOESNT WORK The first line which according to you works fine has a varabiable named value. What is the value you pass in that function? In that second line which you clain that it doesn't work I see an absolute path? Is the website with the pulldown on the same domain as the jsp script that generates the xml file? If not then you're dealing with a crossdomain access. Quote Link to comment https://forums.phpfreaks.com/topic/175204-very-strange-problem-dynamically-generated-xml-not-working/#findComment-923425 Share on other sites More sharing options...
chelnov63 Posted September 23, 2009 Author Share Posted September 23, 2009 hi mate its on the same domain ... its not to do with 'value' as the responseTEXT gives the same response in the alert either way.. ive narrowed it down a bit the differences a bit more: alert(xmlhttpspec.responseText); // THIS ALWAYS SHOWS THE SAME RESULT // FOR STATIC AND DYNAMIC XML THIS says 'string' alert(typeof xmlhttpspec.responseText); // FOR STATIC XML ONLY THIS says 'object' - FOR DYNAMIC nothing is even output here alert(typeof xmlhttpspec.responseXML.documentElement) // FOR STATIC XML THIS says 'object' //WITH DYNAMIC XML IT SEEMS TO BREAK DOWN HERE xmlSpecDoc = xmlhttpspec.responseXML.documentElement; alert("hello there");//WITH DYNAMIC XML THIS DOESNT EVEN SHOW alert(typeof xmlhttpspec.responseXML.documentElement) for static XML gives object whereas for the dynamic text it doesnt even show the alert dialog box. its like the response isnt even XML and thats why it breaks down ? do you think it could be that .jsp isnt sending the correct headers back? Quote Link to comment https://forums.phpfreaks.com/topic/175204-very-strange-problem-dynamically-generated-xml-not-working/#findComment-923429 Share on other sites More sharing options...
RichardRotterdam Posted September 23, 2009 Share Posted September 23, 2009 Hmmm could be. But before you conclude that, what does the XML look like when you directly put the JPS path in your URL? Is it something you can only access locally since I can't request that URL. Another thing, do you have firebug for firefox? With that you can easily check what your request receives by checking the net tab. Quote Link to comment https://forums.phpfreaks.com/topic/175204-very-strange-problem-dynamically-generated-xml-not-working/#findComment-923433 Share on other sites More sharing options...
chelnov63 Posted September 23, 2009 Author Share Posted September 23, 2009 thanks for your help .. it looked like XML was being passed back in fact it was not an XML object.. I think it was just a string.. so i converted the string to an XML object i solved this by doing: var xmlobject = (new DOMParser()).parseFromString(xmlhttpspec.responseText, "text/xml"); and now it works thanks for all your help mate .. appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/175204-very-strange-problem-dynamically-generated-xml-not-working/#findComment-923435 Share on other sites More sharing options...
RichardRotterdam Posted September 23, 2009 Share Posted September 23, 2009 Just one question does it work in IE I see has a different parser. Quote Link to comment https://forums.phpfreaks.com/topic/175204-very-strange-problem-dynamically-generated-xml-not-working/#findComment-923436 Share on other sites More sharing options...
chelnov63 Posted September 23, 2009 Author Share Posted September 23, 2009 thanks for ponting that out .. no it doesnt work in IE how would i do the IE equivalent? thank you Quote Link to comment https://forums.phpfreaks.com/topic/175204-very-strange-problem-dynamically-generated-xml-not-working/#findComment-923457 Share on other sites More sharing options...
RichardRotterdam Posted September 23, 2009 Share Posted September 23, 2009 I think this link will provide you with the answer http://www.w3schools.com/Dom/dom_parser.asp Quote Link to comment https://forums.phpfreaks.com/topic/175204-very-strange-problem-dynamically-generated-xml-not-working/#findComment-923459 Share on other sites More sharing options...
chelnov63 Posted September 24, 2009 Author Share Posted September 24, 2009 thanks for all your help Kat .. that did the trick ..cheers Quote Link to comment https://forums.phpfreaks.com/topic/175204-very-strange-problem-dynamically-generated-xml-not-working/#findComment-923989 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.