Given the following:
What I would like to happen: 1. Find all Span TAGS with class="location" 2. Loop through these and create a JSON string to post to the server
// Determine how many there are
var postText = $("#container").html();
var numFound = $("span.location").length;
var countVar = 0;
//Loop through all the Locations
$( "span.location" ).each( function() {
// Keep a count
countVar = countVar + 1;
// Send at the end
if (countVar == numFound) {
// Send some JSON object to the server [{"locationID":"16","locationDesc":"XXXX"}....]
}
});
Can someone help me understand how to create a JSON object like: [{"locationID":"16","locationDesc":"XXXX"}, {"locationID":"111","locationDesc":"XXXX"}, {"locationID":"12","locationDesc":"XXXX"}, {"locationID":"11","locationDesc":"XXXX"}]
I'd like to build this object via a LOOP, so some way to append over and over.
thxs