Hello,
I hope this isn't too confusing, but i think it's fairly basic. I am trying to pre-populate some data into a form, which was previously entered into a form and then populates the form again on a future date (like a save feature)
So when the user SAVES the form, it inputs into the Database JSON data of the entire form fields and their values.
So inside my code I want to loop through each JSON field that matches inside the XML form and DISPLAY the value.
WHICH in the grand scheme I got it working for the most part. But when I was doing testing, I just used a plain JSON formated file which it works great actually.
But now I need the JSON to be placed into a STRING and then do the same formatting.
SO in short, from a JSON file to a JSON String I need to do this same thing. Eek, I hope this makes some sense to someone.
Here is my code so far. Note: myJSON is short valued for what is inside testJSONData.php
var myJSON = '[{ "rep1FullName": "Justin Giesbrecht", "rep1BrokerNumber": "dc" }]';
$.ajax({
type: "GET",
url: "testJSONData.php",
dataType: "json",
data: myJSON,
success: function(data) {
var j = data[0]; // From the JSON data step into the array []
$.each(j, function(key, value) {
// NOW LETS LOOP THROUGH THE FORM XML
$.ajax({
type: "GET",
url: "forms/NN0821E/application-form-NN0821E.xml",
dataType: "xml",
success: function(xml) {
$(xml).find("field").each(function() {
var formColName = $(this).attr("id");
// Find the matching Nodes in the generated xml and the JSON String
if(formColName == key) {
$("#output").append(formColName +": "+ value +"<br />");
}
}); // End of form xml loop
},
error: function () { alert("Error"); }
}); // End of form xml
}); // END OF JSON LOOP
},
error: function () { alert("Error"); }
}); // End of generated json
Any help would be appreciated! Cheers.