Hi!
I have a Javascript which fetches a remote XML file from my web server using AJAX like so:
- var xmlData;
- var num = 0;
- $(document).ready(function(){
- $.ajax({
- url: 'http://192.168.0.7/xml/xdata.xml',
- type: 'GET',
- dataType: "xml",
- success:function(data){
-
- $(data).find("car").each(function(){
- xmlData = $(this);
- dostuff($xmlData);
- });
- }
- });
- function dostuff(data){
- var binary = data.attr("bin");
- var id = data.attr("id");
- var faultl = data.attr("fault");
- var year = data.attr("year");
- window.resultc.push(binary);
- window.resultv.push(id);
- window.resultf.push(faultl);
- window.resulty.push(year)
- nextCarT(); // This is here to take us to the first object
- }
- function nextBinT(){
- num++;
- document.getElementById("idfc").innerHTML=resultc[num];
- document.getElementById("idfb").innerHTML=resultb[num];
- document.getElementById("idfy").innerHTML=resulty[num];
- xmlData.find("car").eq(num).attr("binary", "1"); // This edits the XML element "binary" to 1
- }
- });
nextBinT is called every time the user presses a button which changes the inner html of the html elements according to the text in the XML row which works fine.
But what I want to do is then after the user is done I have another button which echos out the contents of the edited xmlData var. I have tried:
- function sendoff(){
- console.log($('<xml>').append(xmlData).html());
- }
But that doesnt work. It just echos out the first line of the XML file. I want all the XML echoed out to the console. Any ideas?