Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过php/javascript保存javascript字符串中包含的xml_Javascript_Php_Xml - Fatal编程技术网

如何通过php/javascript保存javascript字符串中包含的xml

如何通过php/javascript保存javascript字符串中包含的xml,javascript,php,xml,Javascript,Php,Xml,我有javascript字符串中的xml页面内容。我需要使用php将其保存到服务器端的my.xml中。但我似乎无法通过POST方法传递xml内容字符串值。我尝试了file_get_contents和curl,但发现这不是我想要的,因为我的xml内容是字符串格式的,而不是在文件中。 有人能帮我把这个字符串保存在javascript中作为正确的xml内容吗 提前谢谢 前 我在下面附上我的代码 Page1.php <form name = "frm_first" method = "POST

我有javascript字符串中的xml页面内容。我需要使用php将其保存到服务器端的my.xml中。但我似乎无法通过POST方法传递xml内容字符串值。我尝试了file_get_contents和curl,但发现这不是我想要的,因为我的xml内容是字符串格式的,而不是在文件中。 有人能帮我把这个字符串保存在javascript中作为正确的xml内容吗

提前谢谢

我在下面附上我的代码

Page1.php

  <form name = "frm_first" method = "POST">
    <input type = "hidden" name = "xml_string">
    ...............


<script type = "text/javascript" language = "javascript">
function getDataXML(){
 xmlString = chart.getDataXML();// This is where I get my xml data into the string
 document.frm_first.xml_string.value = xmlString;
 alert(xml_string); //Good
 document.frm_first.submit();
}
</script>
Page2.php//这是提交帖子的页面

    <?php
    echo print_r($_POST);//xml_string vaiable is empty. Other variables are getting displayed.
    $domtree = new DOMDocument('1.0','UTF-8');
    $domtree->loadXML($_POST['xml_string']);// Error :empty string supplied as input
    $domtree->save("my.xml"); //Yes , I have access to the file.
?>

$\u POST['xml\u string']为空是我的问题。其他变量通过POST传递

当我试图保存一个XML文件时,用PHP调整标题就成功了:

header("Content-Disposition: attachment; filename=file.xml");

但是,应该可以将XML作为字符串发送。您是否收到任何错误消息?

很抱歉回答我自己的问题,但我认为这可能对其他人也有用。 我做了一个if数组\u key\u exists'xml\u string',$\u POST

<?php
if array-_key_exists('xml_string', $_POST) 
{
    echo print_r($_POST);
    $domtree = new DOMDocument('1.0','UTF-8');
    $domtree->loadXML($_POST['xml_string']);
    $domtree->save("my.xml"); 
?>

现在$\u POST变量已正确输入

我没有收到任何错误消息。通过POST.form字段传递后,包含字符串的表单字段为空。。。可以输出$\u POST变量本身吗?我无法想象一个字符串不能用$\u POST发送。也许只是你的表格有问题,而不是帖子。不幸的是,事情就是这样。我还有其他表单字段正在通过并在$\u POST中打印。这个包含xml内容的字符串没有通过/打印。好吧,这是我见过的最奇怪的错误之一,在我的生活中我见过很多狗屎。你能发布包含问题的行吗?我已经在原始问题中添加了我的代码。对于编辑列来说太大了。谢谢你通过。