Jump to content

Very strange problem - dynamically generated XML not working


chelnov63

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.