0

This is the function call

'<div class="commentblock">' +getcomment($(this).attr("id"))+'</div>'  

The function itself:

function getcomment(identifier) {
    var commentmasterstring = "";
    $.ajax({
        type: "GET",
        url: "XML/Thread_" + identifier + ".xml",
        dataType: "xml",
        success: function (xml) {
           {

               $(xml).find('comment').each(function () {
                commentmasterstring += 
                                '<div class="commentmain">' +
                                    '<div class="commentuser-info">' + $(this).find('owner').text() +
                                    '</div>' +
                                    '<div class="data">' +
                                            '<p>' +
                                                $(this).find('data').text() +
                                            '</p>' +
                                            '<p>' +
                                                $(this).find('datetime').text() +
                                            '</p>' +
                                    '</div>' +
                                '</div>'
                                ;
                });

           }

        },
        error: function () {
            alert("The XML File could not be processed correctly.");
        }
    });
    return commentmasterstring;
}  

The XML snip:

<?xml version="1.0"?>
<!--Individual thread-->
<ThreadDetails>
<comment id="29062015080005199730">
    <datetime>June 29 2015, 08:00 AM</datetime> 
    <owner>Jyotirmoy</owner>
    <data>1: one</data> </comment>
<comment id="29062015081941086987">
    <datetime>June 29 2015, 08:19 AM</datetime>
    <owner>Jyotirmoy</owner> 
    <data>1: two</data>
</comment> 
</ThreadDetails>  

After execution, only an empty div gets displayed.I have checked and found the xml path is identified correctly. But, the string value assignment is causing issue. I am not able to figure it out... please help..

sahaj
  • 13
  • 5
  • I debugged in Chrome and found the sequence of execution as follows: commentmasterstring initialization, then the return statement and after that commentmasterstring value update from xml.... – sahaj Jul 01 '15 at 02:50

1 Answers1

0

Try replacing .text() with .html() if you have not already.

Another option using old-school javascript kinda is

$(this).find('datetime').get(0).innerHTML
omikes
  • 8,064
  • 8
  • 37
  • 50