Re: [請益] PHP接收POST過來的XML DOM
---------------------domTest.html--------------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=Big5">
<title>送出XML文件內容</title>
<body>
<script language="JavaScript">
var strXML = "<book>";
strXML = strXML + "<code>F6476</code>";
strXML = strXML + "<booktitle>ASP.NET 2.0網頁製作徹底研究</booktitle>";
strXML = strXML + "<author>陳會安</author>";
strXML = strXML + "<price>660</price>";
strXML = strXML + "</book>";
var parser = new DOMParser();
xmlDom = parser.parseFromString(strXML,"text/xml");
var httpRequest = new XMLHttpRequest();
httpRequest.open("POST", "domTest.php", false);
httpRequest.overrideMimeType('text/xml');
httpRequest.send(xmlDom);
var str = "伺服器狀態: " + httpRequest.status + " - ";
str = str + httpRequest.statusText;
document.write(str + "<br>");
var xmlResult = httpRequest.responseXML;
document.write(xmlResult.documentElement.text);
</script>
</body>
</html>
------------------domTest.php----------------------
<?php
$xmlStr = $HTTP_RAW_POST_DATA;
$simpleXmlElement = simplexml_load_string($xmlStr);
$node = (string)$simpleXmlElement->booktitle;
$titleStr = iconv('utf-8','big5',$node);
echo "<?xml version='1.0' encoding='Big5'?>";
echo "<title>".$titlsStr."</title>";
?>
------------------Firefox 3.6.3-------------
錯誤主控台:「錯誤: xmlResult is undefined」
--------------------------------------------
我又投降了.....怎麼樣才算defined?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.204.82.83
※ 編輯: jerryntcjc 來自: 123.204.82.83 (06/19 03:33)
→
06/19 10:20, , 1F
06/19 10:20, 1F
→
06/19 10:21, , 2F
06/19 10:21, 2F
→
06/19 10:21, , 3F
06/19 10:21, 3F
→
06/19 15:06, , 4F
06/19 15:06, 4F
→
06/19 17:20, , 5F
06/19 17:20, 5F
→
06/19 17:23, , 6F
06/19 17:23, 6F
→
06/19 17:25, , 7F
06/19 17:25, 7F
→
06/19 18:02, , 8F
06/19 18:02, 8F
→
06/20 00:08, , 9F
06/20 00:08, 9F
※ 編輯: jerryntcjc 來自: 123.205.243.236 (06/20 00:10)
→
06/20 00:19, , 10F
06/20 00:19, 10F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章