I have found some similar questions but not quite exactly what I need. I am using AJAX to get the real-time status of property availability. I am getting the response to work as needed and can see the response in the console log. What I am unsure of how to do, is to iterate through the JSON response and append the information to existing element id's to show the availability.
The JSON response is set up like so: [{status: AVAILABLE, category: 21}, {status: SOLDOUT, category: 19}]
$.ajax({
url: bta_obj.ajaxurl,
data: {
'action': 'get_checkfront_items',
'arrive' : arrive,
'depart' : depart,
'categories' : categories,
},
type: "POST",
success:function(data) {
var json = $.parseJSON(data);
$(json).each(function(i,val){
$.each(val,function(k,v){
// here is where the magic needs to happen
});
});
},
error: function(errorThrown){
alert('well darn it....');
}
});
There are div id's that match the category ids. So I first need to determine if the category id matches a div id and then append the status to that div id. Hope that makes sense.
Update
For those who can't see past simple typos in an example JSON response, I have added the brackets that were dearly required....