开发者

can XML be send as response to iframe

I am trying send xml data as response to iframe which is 开发者_StackOverflow中文版dynamically generated. i am sending the follwing data as response

out.println(  
     "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +   
         " <response> " + My_data +  "</response>" ); 

when i check using firebug i only see the follwing innerHTML

<response> My_data </response>

if i am trying to parse the xml i get uncaught exception: Invalid XML error. here is my js

   var xml = this.contentDocument.body.innerHTML,  /* this : iframe id */
       xmlDoc = $.parseXML( xml ), 
       $xml = $( xmlDoc ), 
       $title = $xml.find( "<file-url>" ); 
          alert($title.text());

How can i send XML response & parse.


It is generaly a good idea to use AJAX. How do you actually load that xml into an IFRAME? By using static SRC or Javascript? You have also typos in your code.

  • Javascript command has to end with semicolon not a comma
  • jQuery.find accepts only name of the tag without <>
  • You can prepend a xml header (<?xml ..?>) just before your innerHTML, but its not neccessary here

This should work:

var xml    = this.contentDocument.body.innerHTML,  /* this : iframe id */
var xmlDoc = $.parseXML( xml );
var $xml   = $( xmlDoc );
var $title = $xml.find( "file-url" ); 
      alert($title.text());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜