【发布时间】:2016-09-21 07:28:02
【问题描述】:
我在下面有一个 ajax 请求:
$.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
结果是一个数组:
arr = [{address: '1300 BRYANT ST',
block: '3903',
cnn: '517000',
latitude: '37.7690871267671',
longitude: '-122.411527667132',
received: '2016-05-06' },
more objects];
我想使用地址和块信息并将它们显示为我的 html 页面上的元素列表。
我担心的是,我不想让我的 ajax 函数太长并且在请求中进行 HTML 编码。如何分离 DOM 代码(用于列出信息)和收到的结果?我试图避免编写意大利面条式代码。
【问题讨论】:
标签: javascript jquery html ajax