duaj39673 2012-05-08 23:07
浏览 36
已采纳

PHP似乎不适合使用XML字符串?

I am creating an application where a users draws shapes on a canvas and then saves and retrieves them from a database. The saving part works fine, now though, im trying to load this XML content, Thats where the troubles are starting.

Firstly a user has a list of documents they have created, when clicked it loads that document into the applicaiton to do this, i use the following code, firstly a javascript function which takes the ID of the document, then sends it to a PHP script which retrieves that documents data from a database. The PHP script than loads that documents data into a $_SESSION['data'] variable. Once done, it goes back to the javascript function which redirects the user to application page.

function loadDocument(docID){
    $.ajax({
        url: "load_a_document.php",
        type: "POST",     
        data: { 
            documentID: docID,
        }, 
        success: function(data) 
        {
            alert(data); //THIS DISPLAYS THE XML WITH NO PROBLEMS???
            window.location = "application.php";
        }      
    });
};

The PHP queries the database and retreives the name and XML content of the document, it then does this:

$_SESSION['document_Name'] = $doc_NAME;
$_SESSION['document_XML'] = $doc_DATA;

echo($_SESSION['document_XML']); //this is 'data' on the ajax success call

Now when the PHP is finished it echoes the php context, this shows up in the alert box in the success:{} of AJAX with no problems. Now it takes the user to the actual application which begins like so:

<?php 
session_start();

$document_Name = $_SESSION['document_Name'];
$document_Data = $_SESSION['document_XML'];
?>
<script>
    alert(" <?php echo $document_Name; ?> "); //WORKS FINE
    alert(" <?php echo $_SESSION['document_Name']; ?> ") //WORKS FINE

    //alert(" <?php echo $document_Data; ?> "); //STOPS THE PAGE LOADING
    //alert(" <?php echo $_SESSION['document_XML']; ?> ") //STOPS THE PAGE LOADING
</script>

Fetching the first two items, there are no problems, as soon as XML data is printer then their is a real problem. I dont understand why the loadDiagram() can alert () the XML but my application page cannot. Has the data been corrupted somehow?

Thanks for any feedback.

  • 写回答

1条回答 默认 最新

  • dongqing6755 2012-05-08 23:10
    关注

    You probably have quotes in the string that's causing the problem. Try

    alert(<?php echo json_encode($document_Data) ?>);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助