我有一个读取 xml 文件的post()调用,因为这是一个正确的 xml 文件,所以我应该能够并且我应该使 dataType="xml"。但这打破了电话。如果我使 dataType="text" 效果很好。有没有人看到问题?
$.post('loadPage.php', { siteName : siteName},function(xml) {
Status2$.html(xml);
var bdystyle = $(xml).find("bodyStyle")[0].textContent;
var canvasstyle = $(xml).find("canvasStyle")[0].textContent;
},
"text");
php是:
<?php
$siteName = $_POST['siteName'];
$fileName = "{$siteName}_sav.xml";
$fileSize = filesize($fileName);
$filePath = $_SERVER['DOCUMENT_ROOT'] . "/" . $fileName;
$site_fp = fopen( $filePath, 'r');
$xml = fread($site_fp, $fileSize);
echo $xml;
?>
xml文件是:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<bodyStyle>background-image: none; background-color: rgb(255, 254, 253); cursor: auto;</bodyStyle>
<canvasStyle>background-image: none; background-color: rgb(255, 26, 0);</canvasStyle>
<canvasData>This is where the canvas html would go.</canvasData>
</root>