我正在使用jquery ajax使用text()但是在XML中编写的任何html都不会呈现?

时间:2021-10-02 19:56:43

So I have Jquery Ajax working real nice, but an issue I am having is in my XML if I want to bold a work or Italicize a sentence, if I do it in the XML using HTML tags it will not show up. I am pretty sure it is due to using the .text(). Any suggestions on a work around for this?

所以我让Jquery Ajax工作真的很好,但我遇到的问题是我的XML,如果我想加粗工作或斜体化一个句子,如果我在XML中使用HTML标签这样做就不会出现。我很确定这是因为使用了.text()。有关解决此问题的任何建议吗?

$(document).ready(function(){
   $.ajax({
    type: "GET",
    url: "xml/sites.xml",
    dataType: "xml",
    success: function(xml) {
     $(xml).find('site').each(function(){

    $(this).find('desc').each(function(){
       var brief = $(this).find('brief').text();
       var long = $(this).find('long').text();
       var url = $(this).find('url').text();
       $('<div class="brief"></div>').html(brief).appendTo('#link_'+id);

I took out the .text() and it worked but it is not showing up in IE????? does that make any sense????????????

我拿出了.text()并且它有效但它没有出现在IE浏览器中?????这有任何意义吗????????????

2 个解决方案

#1


0  

If <brief> is meant to contain HTML, don't call .text() at all. Try simply:

如果 意味着包含HTML,请不要调用.text()。试试简单:

var brief = $(this).find('brief');
$('<div class="brief"></div>').append(brief);

#2


0  

Have you tried the ".html()" method instead?

您是否尝试过“.html()”方法?

$(document).ready(function(){
  $.ajax({ type: "GET", url: "xml/sites.xml", dataType: "xml", success: function(xml) {
    var brief, long, url;
    $('site desc', xml).each(function(){
      var brief = $('brief', this).html();
      var long  = $('long', this).html();
      var url   = $('url', this).html();
      $('<div class="brief"></div>').html(brief).appendTo('#link_'+id);
    });
  });
});

#1


0  

If <brief> is meant to contain HTML, don't call .text() at all. Try simply:

如果 意味着包含HTML,请不要调用.text()。试试简单:

var brief = $(this).find('brief');
$('<div class="brief"></div>').append(brief);

#2


0  

Have you tried the ".html()" method instead?

您是否尝试过“.html()”方法?

$(document).ready(function(){
  $.ajax({ type: "GET", url: "xml/sites.xml", dataType: "xml", success: function(xml) {
    var brief, long, url;
    $('site desc', xml).each(function(){
      var brief = $('brief', this).html();
      var long  = $('long', this).html();
      var url   = $('url', this).html();
      $('<div class="brief"></div>').html(brief).appendTo('#link_'+id);
    });
  });
});