Dear all,
I am totally new to jQuery and no good knowledge on javascript. However, I was assigned a task, to convert a javascript program to jQuery due to compatibility problem on browsers like Chrome and Safari.
My program originally use javascript xmlDoc.load(‘….’) to read XML file, and then use document.write statement to write html tables on client side. Something like this (the sample below may got lots of syntax problem as I jut want to show the major part):
[CODE]
document.write(‘<TABLE >’);
var y=x[0].getElementsByTagName(‘NoOfRows’);
for (i=0; i<=noofrows-1 && i<=y.length-1; i++){
document.write(‘ <TD>’);
document.write(z[j].getElementsByTagName(‘RecordDetails’)[0].childNodes[0].nodeValue;
}
Now I changed to use jQuery, I can read the XML file elements. However, when I try to write the table, it failed:
[CODE]$(document).ready(function(){
$.ajax({
type: “GET”,
url: “../tdata/01DATA.XML”,
dataType: “xml”,
success: function(xml) {
$(‘.P1’).append(‘<table><tr>’);
$(‘.P1’).append(‘<td ALIGN=CENTER><B>Heading 1</B></FONT></TD>’);
$(xml).find(‘MYDATA’).each(function(){
var noofcremator = $(this).find(“NOOFDATA”).text();
var noofsession = $(this).find(“NOOFSESSION”).text();
for (i=1; i<=5; i++){
$(‘.P1’).append(‘<TD><B> Session ‘ + i + ‘</B></FONT></TD>’);
}
}); //close each(
$(‘.P1’).append(‘</tr></table>’);
}
});
});
After surf on the net, I find that when I use two statement of .append, the TABLE Tag will not function as I expected.
e.g.
[CODE] $(“p”).append(” <Table><TD>TEST 1</TD>”);
$(“p”).append(” <TD>TEST 2</TD></Table>”);
is different from
$(“p”).append(” <Table><TD>TEST 1</TD> <TD>TEST 2</TD></TABLE>”);
Is there any way I can build a table using separated append statements (or any statement in jQuery)?
This maybe a totally newbie question but thank you very much if for any input you can provide.