I have been searching all day, and have found some promising options, that haven't panned out for me (ie. Is it possible to add,delete xml nodes with jquery $.ajax?). I believe my biggest issue is not being overly familiar with AJAX or XML, but here is problem simplified: I need to update a local XML page through an HTML page (without use of PHP or other server-side tools). I am working within a vendor-provided solution (so I cannot modify the product much).
Here's snippets of what I have working: mobileSettings.xml:
<settings>
<application>
<firstCase>PublicMonitor</firstCase>
</application>
</settings>
customSettings.js:
function loadSettings()
{
$.ajax({
type: "GET",
url: '../configurations/mobileSettings.xml',
dataType: "xml",
success: function(xml) {
$(xml).find('firstCase').each(function () {
startPage.value = $(this).text();
});
}
});
}
What I cannot get to work is also a part of the same .js, but it is for Save. You can see by the commented code a number of failed attempts. (Between the Load and Save, the user can change a simple dropdown box to select a new value.):
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;
});
}
});
}
My assumption is that there is nothing here that is sending the data to the XML. I have been searching tirelessly, but I have not found a solution that actually works. Again, I cannot use server-side scripting, so the solution must be AJAX/JQuery/Javascript ... which I do not know will work.
Thanks in advance.
EDIT 07.02.2015
I believe I may not have been as clear as I should have been. My problem lies in changing the .xml file through AJAX, etc. I know how to manipulate the data on the user page, but I need the user to be able to declare a new value which will need to be saved to the existing .xml page. The user has a dropdown menu which will provide them with valid values and upon Submit, the XML file needs to change the firstCase node to something else:
<settings>
<application>
<firstCase>PrivateMonitor</firstCase>
</application>
</settings>
The fiddle provided in the comments (http://jsfiddle.net/py5dvk6e/) works well to create the xml string, but I do not know how to save that string to the .xml file called in the customSettings.js file (above).