简体   繁体   English

可以将XML发送为对iframe的响应

[英]can XML be send as response to iframe

I am trying send xml data as response to iframe which is dynamically generated. 我正在尝试发送xml数据作为对动态生成的iframe响应。 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 当我使用firebug检查时,我只看到下面的innerHTML

<response> My_data </response>

if i am trying to parse the xml i get uncaught exception: Invalid XML error. 如果我尝试解析xml,则会遇到uncaught exception: Invalid XML错误。 here is my js 这是我的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. 我如何发送XML响应和解析。

It is generaly a good idea to use AJAX. 通常,使用AJAX是个好主意。 How do you actually load that xml into an IFRAME? 您实际上如何将该xml加载到IFRAME中? By using static SRC or Javascript? 通过使用静态SRC还是Javascript? You have also typos in your code. 您的代码中也有错别字。

  • Javascript command has to end with semicolon not a comma Javascript命令必须以分号结尾而不是逗号
  • jQuery.find accepts only name of the tag without <> jQuery.find仅接受标记名称,而不包含<>
  • You can prepend a xml header (<?xml ..?>) just before your innerHTML, but its not neccessary here 您可以在您的innerHTML之前添加一个xml标头(<?xml ..?>),但这在这里不是必需的

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());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM