Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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
通过Javascript/JQuery/AJAX更新XML节点_Jquery_Ajax_Xml - Fatal编程技术网

通过Javascript/JQuery/AJAX更新XML节点

通过Javascript/JQuery/AJAX更新XML节点,jquery,ajax,xml,Jquery,Ajax,Xml,我已经搜索了一整天,发现了一些有希望的选择,但还没有为我找到(即)。我认为我最大的问题是不太熟悉AJAX或XML,但这里有一个简化的问题: 我需要通过HTML页面更新本地XML页面(不使用PHP或其他服务器端工具)。我在供应商提供的解决方案中工作(因此我无法对产品进行太多修改) 以下是我的工作片段: mobileSettings.xml: <settings> <application> <firstCase>PublicMonitor</fir

我已经搜索了一整天,发现了一些有希望的选择,但还没有为我找到(即)。我认为我最大的问题是不太熟悉AJAX或XML,但这里有一个简化的问题: 我需要通过HTML页面更新本地XML页面(不使用PHP或其他服务器端工具)。我在供应商提供的解决方案中工作(因此我无法对产品进行太多修改)

以下是我的工作片段: mobileSettings.xml:

<settings>
 <application>
   <firstCase>PublicMonitor</firstCase>
 </application>
</settings>
我无法工作的部分也是同一个.js的一部分,但它是为了保存。您可以通过注释的代码看到许多失败的尝试。(在“加载”和“保存”之间,用户可以更改一个简单的下拉框以选择新值。):

函数保存设置()
{
startP=startPage.value;
$.ajax({
键入:“放置”,
url:“../configurations/mobileSettings.xml”,
数据类型:“xml”,
成功:函数(xml){
$(xml).find('firstCase').each(函数(){
//$(this).text(startP);
$(this.attr(startP);
//$(this).find('firstCase').text(“test”);
//$(this.setAttribute(“firstCase”、“test”);
//var elem=document.createElement('firstCase');

//xml.find('application').append(elem);//Appends)可以很好地创建xml字符串,但我不知道如何将该字符串保存到customSettings.js文件(上面)中调用的.xml文件中。

尝试使用$.parseXML(xml)而不是$(xml)也许我遗漏了什么(这是一个很大的可能性),但是在哪里;一般来说,用$.parseXML(xml)替换我的$(xml)?这似乎并没有达到我想要的效果,但是,这可能是因为我对这个主题缺乏知识。我签出了[link],但它没有为我提供一种实际更改XML的方法。我可以在.js/.htm中操作数据,但这是这些更改的实际保存(到XML)这是我头疼的地方。谢谢你,很抱歉我的无知。试试这个。过去几个小时我一直在玩小提琴,但仍然有相同的问题。我将编辑我的原稿,也许可以更好地澄清我的问题。小提琴工作如我所料,但我遇到的问题是对.xml文件本身的修改。(一切都是客户端的,我认为这应该是可以做到的,但这远不是我的信心所在。首先,您的xml格式不正确。您需要正确地查看标记。标记是打开的,但从不关闭。您的xml无效,这可能是您无法更新它的原因。)
function loadSettings()
{
    $.ajax({
        type: "GET",
        url: '../configurations/mobileSettings.xml',
        dataType: "xml",
        success: function(xml) {
            $(xml).find('firstCase').each(function () {
                startPage.value = $(this).text();
            });
        }
    });
}
function saveSettings()
{
    startP = startPage.value;
    $.ajax({
        type: "PUT",
        url: '../configurations/mobileSettings.xml',
        dataType: "xml",
        success: function(xml) {
            $(xml).find('firstCase').each(function () {
//               $(this).text(startP);
               $(this).attr(startP);
//             $(this).find('firstCase').text("test");
//              $(this).setAttribute("firstCase", "test");
//                var elem = document.createElement('firstCase');
//                xml.find('application').append(elem); // Appends <app></app> to <layout>
//                $(this).find('firstCase').text() = startPage.value;
            });
        }
    });
}
<settings>
 <application>
   <firstCase>PrivateMonitor</firstCase>
 </application>
</settings>