I have an ajax call:
$.ajax({ type: 'POST', url: 'submit.php', data: { templateID: url, submitType: 208 }, success: function(data) { console.log(data); } });
It returns:
{"subject":"Test 123","body":"<p>looks good!<\/p>"}
But how do I reference the subject and body columns?
Well we first have to parse the response then we can output it to the console:
$.ajax({ type: 'POST', url: 'submit.php', data: { templateID: url, submitType: 208 }, success: function(data) { var obj = jQuery.parseJSON( data); console.log( obj.subject); } });
Or if you prefer to see this in an alert:
$.ajax({ type: 'POST', url: 'submit.php', data: { templateID: url, submitType: 208 }, success: function(data) { var obj = jQuery.parseJSON( data); alert( obj.subject); } });