Here is a piece of jquery code from my html page
$.ajax({
url: 'userlist.php',
type: 'post',
data: 'id='+extr,
success: function(results){
$("#uservidshow").text("Page Title: "+$(results).find("vidlist").attr("title"));
//$("#uservidshow").text(results);
$(results).find("vids").each(function(){
$("#uservidshow").append("<br/><br/>Video Name: "+$(this).attr("vtitle")+"<br/>Link: "+$(this).attr("link")+"<br/>Description: "+$(this).find("descr").text()+"<br/><br/>");
});
}
});
--- Here is the output that gets displayed in div#uservidshow ---
Page Title: undefined
Video Name: Kids video
Link: http://www.youtube.com/watch?v=PIchX1LX0
Description:
My question is:
Why do I get 'undefined' page title?
Why do i get a blank under the description instead of displaying cdata content?
--- Here is a piece of code from userlist.php ---
<?php
$getid=$_POST['id'];
....
[few lines of code]
....
$pickfrmtab= mysql_query("SELECT * FROM mytable WHERE userid='$getid'");
if(mysql_num_rows($pickfrmtab)==1){
while($row = mysql_fetch_array($pickfrmtab)){
echo htmlspecialchars_decode($row['pagecontent'], ENT_QUOTES); //'pagecontent' contains my xml string
}
}else{
echo "Unable to get PLAYLIST";
}
?>
--- Here is the XML string that is stored in database under the column name 'pagecontent'---
<?xml version='1.0' encoding='UTF-8' ?><vidlist title='My Fav Videos'>
<vids link='http://www.youtube.com/watch?v=PIchX1LX0' vtitle='Kids video'>
<descr><![CDATA[this is nice]]></descr>
</vids>
<comment allow='no'></comment>
</vidlist>
As you might have guessed, i have applied htmlspecialchars() to the actual xml string before inserting it into database
$xmldata="<?xml version='1.0' encoding='UTF-8' ?>".$_POST['actualxmlstrng'];
$xmldata_safe=htmlspecialchars($xmldata, ENT_QUOTES);
//inserted $xmldata_safe into the datacbase field 'pagecontent' SUCCESSFULLY
Just to give you an idea, this is what $xmldata looks like before applying htmlspecialchars:
<?xml version='1.0' encoding='UTF-8' ?>
<vidlist title='My Fav Videos'>
<vids link='http://www.youtube.com/watch?v=PIchX1LX0' vtitle='Kids video'>
<descr><![CDATA[this is nice]]></descr>
</vids>
<comment allow='no'></comment>
</vidlist>