Here’s my HTML. Apologies for formatting – this is my first-ever question!
<div id="Template">
<table cellspacing="0" width="100%">
<tr valign="top">
<td>
<span class="Name" ></span>
(<span class="Id"></span>)
<span class="Addr" ></span><br>
<span class="City" ></span>,
<span class="State" ></span>
<span class="Zip" ></span><br>
</td>
</tr>
</table>
Here’s my JQuery so far:
$.getJSON(serverURL,{ id: X },
function(data) {
$.each(data, function(key,val){
var clonedDiv= $('#Template').clone();
//"Each" below represents the various data members of the object currently being processed.
$.each(val,function(key2,value){
//Below are the only Keys needed so skip the rest.
if (key2=='Id' || key2=='Name' || key2=='Addr' || key2=='City' || key2=='State' || key2=='Zip'){
alert('Key2:'+key2+' val2:'+JSON.stringify(value));
///INSERT VALUE INTO NEWLY-CLONED DIV SPAN CHILD HERE???
}
});
$('#TemplatePrev').append(clonedDiv);
});
})
.success(function() {
alert('success');
})
.error(function() { alert('error'); })
.complete(function() {
//alert('complete');
});
When the above is run, there are 10 objects returned by the JSON call and the JQuery clones 10 DIVs that look like the #Template div. However, I need to shove that JSON Stringified value into each span dynamically. Any idea how to do this? I’ve been at this for 2 hours before breaking down and posting here. Thanks in advance!
Have you tried the following?