如何在HTML中存储响应数据?
在JS文件中,我收到了data.firstname
,data.street
,data.city
等响应。但我不知道如何在HTML中添加响应数据。
HTML
<h5>Firstname</h5>
<h6><span class="location semi-bold"><i class="fa fa-map-marker"></i> Street, City</span></h6>
JS档案
var freetext = $('#freetext').val();
var id = $(":hidden", this).val();
var token = $('input[name=_token]').val();
var dataString = 'freetext=' + freetext + '&id=' + id + '&token=' + token;
$.ajax({
type: "post",
url: "{!! URL::to('socialfreetext') !!}",
data: dataString,
success: function (data) {
alert(data.firstname);
alert(data.street);
alert(data.city);
}
});
答案 0 :(得分:1)
在您要填写回复的位置放置一个范围:
<h5>Firstname</h5>
<h6>
<span class="location semi-bold"><i class="fa fa-map-marker"></i> <span id="address">Street, City</span></span></h6>
然后执行:
$("#address").text(data.street + ", " + data.city);