XML 파일에 작성해야하며 JavaScript로 작성해야하는 유일한 방법은 AJAX를 사용하는 것입니다. 마지막으로 그것을 사용하고 문자 자체 대신 문자에 대한 HTML 코드를 얻을 수 있도록 텍스트를 구문 분석 할 수 없습니다.JQuery AJAX를 사용하여 파일에 XML을 작성하십시오.
내가 무엇을 가지고 :
AJAX
$.ajax({
type: 'POST',
url: "writeXML.php",
dataType: 'xml',
data: {filename: "test.xml", content: listXML},
error: function() {
alert("Unknown error. Data could not be written to the file.");
},
success: function() {
window.open("test.xml");
}
});
PHP 파일
내가 달성하기 위해 노력하고 무엇<?php
$fileName = htmlspecialchars($_POST["filename"]);
$content = htmlspecialchars($_POST["content"]);
$file = fopen($fileName, "w");
fwrite($file, $content);
fclose($file);
?>
:
<?xml version="1.0" encoding="UTF-8"?>
<SeriesList>
<Series>
<title>Ookami to Koushinryou</title>
<score>6</score>
<episodes>7</episodes>
<episodesTotal>23</episodesTotal>
<episodeLength>20</episodeLength>
<timesWatched>dropped</timesWatched>
</Series>
<Series>
<title>Speed Grapher</title>
<score>5</score>
<episodes>7</episodes>
<episodesTotal>24</episodesTotal>
<episodeLength>20</episodeLength>
<timesWatched>dropped</timesWatched>
</Series>
</SeriesList>
을 내가 무엇을 얻을 :
<?xml version="1.0" encoding="UTF-8"?>
<SeriesList>
<Series>
<title>Ookami to Koushinryou</title>
<score>6</score>
<episodes>7</episodes>
<episodesTotal>23</episodesTotal>
<episodeLength>20</episodeLength>
<timesWatched>dropped</timesWatched>
</Series>
<Series>
<title>Speed Grapher</title>
<score>5</score>
<episodes>7</episodes>
<episodesTotal>24</episodesTotal>
<episodeLength>20</episodeLength>
<timesWatched>dropped</timesWatched>
</Series>
</SeriesList>
그럼 어떻게해야합니까? 나는 utf8_encode()를 시도했으나 작동하지 않았고 PHP로 다목적이라고 부르는 것이 아니기 때문에 아이디어가 없습니다.
내가 생각한 모든 것을 검색했지만 지금까지 아무 것도 작동하지 않았습니다.
미리 감사드립니다.
코드 복사 복사시 발생합니다. 정말 고마워요. –