如何在XHTML中显示P标签内容?

时间:2014-03-14 17:30:53

标签: php jquery dom

我实际上对我的代码感到困惑......我有一个包含Ajax和JQuery的文件english.html,它执行了一些处理..当english.html文件有.html扩展名时,该过程正常,但是当我将该扩展名更改为.xhtml,它不输出任何内容..

//english.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org  /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>
    <meta charset="utf-8" />    
    <title>Mobile View</title>  
    <meta name="viewport" content="width=device-width, initial-scale=1" /> 

    <link rel="stylesheet" href="styless.css"/>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>                         
        function myPara() {
            var request = $.ajax({
                url: "dom.php",
                type: "GET",           
                dataType: "html"
            });

            request.done(function(msg) {
                $("#para").html(msg);         
            });

            request.fail(function(jqXHR, textStatus) {
                alert( "Request failed: " + textStatus );
                });
        }

    </script>   
</head>
<body id="home"  bgcolor="white "> 
<div class="wrapper">


    <div  id="para" style="width:auto; height:200px; overflow: auto;" >

        <script>myPara();</script>
    </div>

</div>

</body>
</html> 

Here is the code for dom.php
//dom.php
<?php
header('Content-Type:text/html;charset=utf-8');
$xhtml = '<html>
<body>
<para>This is a paragraph</para>
<para>This is another paragraph</para>
</body>
</html>';

$doc = new DOMDocument();

libxml_use_internal_errors(true);
$doc->loadHTML($xhtml);
$doc->preserveWhiteSpace=false;
libxml_use_internal_errors(false);


$xpath = new DOMXpath($doc);

$elements = $xpath->query("//para");
foreach ($elements as $node){
echo $node->nodeValue. "<br/>";
}
?>

0 个答案:

没有答案