如何用ajax更新XML文件?

时间:2021-04-27 13:32:25

I have xml storage with in this format

我有这种格式的xml存储

<Contacts>
     <Contact>
         <![CDATA["Some HTML"]]>
     </Contact>
     <Contact>
         <![CDATA["Some HTML"]]>
     </Contact>
</Contacts>

I am using XMLHttpRequest to read the data and put it inside a "div" on the page. Now I make some changes on it via JavaScript and I would like to know how can I update the changes made back to the XML file from where I took the data. I've been googling a lot but I have problems understanding those forums because they are not describing examples similar like mine.

我正在使用XMLHttpRequest读取数据并将其放在页面上的“div”中。现在我通过JavaScript对它进行一些更改,我想知道如何更新从我获取数据的位置返回到XML文件的更改。我一直在谷歌上搜索,但我在理解这些论坛时遇到了问题,因为他们没有像我一样描述类似的例子。

2 个解决方案

#1


0  

Try using a ajax call which you give the xml data. You can then save the data using simplexml http://nl.php.net/manual/en/book.simplexml.php or using http://nl.php.net/manual/en/book.domxml.php

尝试使用您提供xml数据的ajax调用。然后,您可以使用simplexml http://nl.php.net/manual/en/book.simplexml.php或使用http://nl.php.net/manual/en/book.domxml.php保存数据。

#2


0  

Leave the "retrieving" your XML on JavaScript, and "saving changes" on PHP. Using jQuery you just $.get() your XML file, and when you save it (let it be .click, .live('click') etc.) you $.post() strings you wrote in some input to something like save_xml.php. There are some tools for working with XML files in PHP. If you get on well with Smarty, I advise you to keep sort of my_xml_template.tpl , which after smarty->fetch you save in a file with file_put_contents(). Cheers.

保留在JavaScript上“检索”XML,并在PHP上“保存更改”。使用jQuery你只需$ .get()你的XML文件,当你保存它(让它是.click,.live('click')等)你在一些输入中写的$ .post()字符串就像save_xml.php。有一些工具可以在PHP中使用XML文件。如果你与Smarty相处得很好,我建议你保留my_xml_template.tpl,在smarty-> fetch之后你将其保存在一个带有file_put_contents()的文件中。干杯。

#1


0  

Try using a ajax call which you give the xml data. You can then save the data using simplexml http://nl.php.net/manual/en/book.simplexml.php or using http://nl.php.net/manual/en/book.domxml.php

尝试使用您提供xml数据的ajax调用。然后,您可以使用simplexml http://nl.php.net/manual/en/book.simplexml.php或使用http://nl.php.net/manual/en/book.domxml.php保存数据。

#2


0  

Leave the "retrieving" your XML on JavaScript, and "saving changes" on PHP. Using jQuery you just $.get() your XML file, and when you save it (let it be .click, .live('click') etc.) you $.post() strings you wrote in some input to something like save_xml.php. There are some tools for working with XML files in PHP. If you get on well with Smarty, I advise you to keep sort of my_xml_template.tpl , which after smarty->fetch you save in a file with file_put_contents(). Cheers.

保留在JavaScript上“检索”XML,并在PHP上“保存更改”。使用jQuery你只需$ .get()你的XML文件,当你保存它(让它是.click,.live('click')等)你在一些输入中写的$ .post()字符串就像save_xml.php。有一些工具可以在PHP中使用XML文件。如果你与Smarty相处得很好,我建议你保留my_xml_template.tpl,在smarty-> fetch之后你将其保存在一个带有file_put_contents()的文件中。干杯。