简体   繁体   中英

how to append multiple string to an HTML element in jquery?

Here, using ajax call I am getting the data as json object. For example, in userid, it returns some value. But in address value, it returns like addr1, addr2, addr3 (3 values). So how can I append these 3 values in html element and also it should be in String format tostring()

<script>
$(document).ready(function(){
    $.ajax({
          type: "GET",
          url: "Controller?token=123",
          dataType: 'json',
          success: function(data){

          $('#userid').html(data.userid.toString());          
          $('#addr').html(data.addr1.append(addr2));
          },
          error:function(){
            alert("Sorry!");
          }
        });

});
</script>

Example strings:

addr1: 124, WELINGTONE STREET

addr2: NEWYORK

addr3: OH 12454-8787

These values are get from json object with the key names as addr1, addr2 and addr3 I need to append the key not values.

像这样吗

$('#addr').html([data.addr1,data.addr2,data.addr3].join("<br>"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM