1

嗨,我正在使用 JSON 和 ajax 从数据库中检索一些数据。当我获取我需要的信息时,我希望它显示在 div 中的新行上,我将其放入。

此刻,邮政编码只是相互覆盖。

$.ajax({    
              url: 'process.php',
              type: 'GET',
              data: 'address='+ criterion,
              dataType: 'json',
              success: function(data) 
              {
                  jQuery.each(data, function()
                  {
                    $('#carParkResults').html("Postcode " + data[count].postcode);
                    codeAddress(data[count].postcode);
                    alert(count);
                    count++;
                  });
              },
              error: function(e) 
              {
                //called when there is an error
                console.log(e.message);
                alert("error");
              }
    });
4

2 回答 2

2

使用 append / appendTo 将元素添加到 DOM 元素,而不覆盖元素的现有子元素。

 $('<p>').text("Postcode " + data[count].postcode).appendTo('#carParkResults');
于 2012-05-09T17:21:01.063 回答
0

您需要使用 .append(),.html() 总是会替换 div 内的所有 html。

于 2012-05-09T17:20:35.137 回答