Javascript&XML

edited 十月 2013 in Javascript
請問為什麼我的結果一直是『1』,請告訴我問題出在哪?並告訴我如何解決!(順道一提,我是用Linux跑)以下是我的程式碼

index.php的程式碼
<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>無標題文件</title>



</head>



<body>


<table border="1">

<script language="javascript">
var httprequest
httprequest=new XMLHttpRequest()
httprequest.open("get","test.xml",false)
document.write(httprequest.readyState + "<br>")
httprequest.send()
document.write(httprequest.readyState + "<br>")
xmldom=httprequest.responseXML
var objnode=xmldom.documentElement.childNodes
for(i=0;i<objnode.length;i++){
document.write("<tr><td>")
document.write(objnode.item(i).nodeName + "</td><td>")
document.write(objnode.item(i).text + "</td></tr>")
}

</script>

</table>

</body>

</html>



test.xml的程式碼
<?xml version="1.0" encoding="utf-8" ?>
<yushi>
<book code="dd">
<title>YUSHI LIFE</title>
</book>
<book code="ss">
<author>Lin-Yushi</author>
</book>
<book code="gg">
<content>The Life of Yushi</content>
<publish>Lin</publish>
</book>
</yushi>

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=3655

評論

Sign In or Register to comment.