使用 javascript 加载/修改/保存 XML

发布于 2024-12-11 04:02:32 字数 628 浏览 0 评论 0原文

在这个问题被标记为重复之前,我很抱歉!我已经阅读了所有重复的问题,如果有的话,它让我更加困惑。所以也许这个问题略有不同。

我编写了一个小型 Javascript 库,它可以进行 ajax 调用,并从 facebook 图 API 中获取和解析信息。

这使我几乎可以在我的网页上显示我的所有页面状态。然而,我即将推出,并且我已经做了尽可能多的测试。

然而。我确信会发生错误,而且我已经写了很多错误捕获等等等等。

我想做的是将所有错误保存在 xml 文件中。

因此,当发生错误时,我希望 javascript 从服务器加载 xml 文件,添加错误,然后保存更改。

我知道如何使用 XmlHttpRequests 加载 xml 文档,并且我确信我可以弄清楚如何仅通过使用 dom 操作来修改 xml。

我真正想知道的是。我如何保存这些更改?它会自动保存吗?

或者我是否必须“以某种方式”将更新的 xml 版本传递给 php 并保存它?

我不太确定该怎么做。

我会使用 mySQL 和 php,但这意味着“以某种方式”将错误信息传递给 php,然后保存它。

然而,我更喜欢 XML,因为我是唯一会读取 xml 文件的人。

非常感谢。

亚历克斯

Before this question gets stamped as a duplicate, I am sorry! I've read ALL the duplicate questions and if anything, it has confused me even more. So maybe this question is slightly different.

I've written a little Javascript library that makes ajax calls and fetches and parses information from the graph facebook API.

This enables me to pretty much show all my page status' on my web page. However I'm just about to launch, and I have done as much testing as I can.

However. I'm sure errors will occur, and I've written many error catches blah blah blah.

What I want to do, is save all my errors in a xml file.

So when an error occurs, I want the javascript to load the xml file from the server, add the errors, then save the changes.

I know how to load the xml doc using XmlHttpRequests, And I'm sure I can figure out how to modify the xml just by using dom manipulation.

All i really want to know is. How do i save these changes? does it save automatically?

Or do i have to "somehow" pass the updated xml version to php and get that to save it?

Im not quite sure how to go about it.

I would use mySQL and php but that means "somehow" passing the error information to php, then saving it.

However id much prefer XML seeing as I'm the only person that will be reading the xml file.

Thanks very much.

Alex

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想念有你 2024-12-18 04:02:32

或者我是否必须“以某种方式”将更新的 xml 版本传递给 php 并保存它?

是的,您需要使用 XML HTTP 请求将 XML DOM 发送到 PHP 可以保存它的服务器:

function postXML(xmlDOM, postURL, fileName, folderPath){
try{     
  // Create XML HTTP Request Object
  oXMLReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
  // Issue Synchronous HTTP POST 
  oXMLReq.open("POST",postURL,false);
  // Set HTTP Request Headers
  if(fileName != null){ oXMLReq.setRequestHeader("uploadFileName", fileName); }        // What should file be named when saved on server?
  if(folderPath != null){ oXMLReq.setRequestHeader("uploadDir", folderPath); }   // What folder should file be saved in on server?
  // SEND XML
  ///WScript.Echo(xmlDOM.xml);
  oXMLReq.send(xmlDOM.xml);
  return oXMLReq.responseText;
 }catch(e){
  return "postXML failed - check network connection to server";
 }
}

Or do i have to "somehow" pass the updated xml version to php and get that to save it?

Yes, you'll want to use an XML HTTP request to send the XML DOM to the server where PHP can save it:

function postXML(xmlDOM, postURL, fileName, folderPath){
try{     
  // Create XML HTTP Request Object
  oXMLReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
  // Issue Synchronous HTTP POST 
  oXMLReq.open("POST",postURL,false);
  // Set HTTP Request Headers
  if(fileName != null){ oXMLReq.setRequestHeader("uploadFileName", fileName); }        // What should file be named when saved on server?
  if(folderPath != null){ oXMLReq.setRequestHeader("uploadDir", folderPath); }   // What folder should file be saved in on server?
  // SEND XML
  ///WScript.Echo(xmlDOM.xml);
  oXMLReq.send(xmlDOM.xml);
  return oXMLReq.responseText;
 }catch(e){
  return "postXML failed - check network connection to server";
 }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文