I have an ajax request below:
$.ajax({
url: "/geodata",
data: {'lat':lat,'lng':lng},
type: "POST",
success: function(result) {
if ( typeof result == "string") {
console.log("helo");
} else {
// do things with the result here
the result is an array as such:
arr = [{address: '1300 BRYANT ST',
block: '3903',
cnn: '517000',
latitude: '37.7690871267671',
longitude: '-122.411527667132',
received: '2016-05-06' },
more objects];
I want to use the address and block information and display them as a list of elements on my html page.
My concern is, I do not wish to make my ajax function too long and do my HTML coding inside the request. How can I separate the DOM code (for listing the information) and the result received? I am trying to avoid writing spaghetti code.