これは私のhtmlページからのjqueryコードの一部です
$.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/>");
});
}
});
--- div#uservidshow に表示される出力は次のとおりです ---
ページタイトル:未定
ビデオ名: キッズビデオ
リンク: http://www.youtube.com/watch?v=PIchX1LX0
説明:
私の質問は:
「未定義」のページ タイトルが表示されるのはなぜですか?
cdata コンテンツを表示するのではなく、説明の下に空白が表示されるのはなぜですか?
--- これは 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";
}
?>
--- これは、列名「pagecontent」でデータベースに格納されている XML 文字列です---
<?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>
ご想像のとおり、データベースに挿入する前に、実際の xml 文字列に htmlspecialchars() を適用しました。
$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
参考までに、htmlspecialchars を適用する前の$xmldataは次のようになります。
<?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>