我有这个ajax调用,它返回一个简短的句子,用于用户描述。通过调试控制台,我可以看到我正在返回正确的数据。当我尝试将此数据附加到html <p>
标记时,就会出现我的问题。我在使用JQuery时尝试了.append和.text。到目前为止,我还没有运气,我要去哪里错了?
$('#scenarioDropdownList').change(function () {
var scenarioId = $('#scenarioDropdownList option:selected').attr('id');
getscenarioDescription(scenarioId);
getData(scenarioId);
});
function getscenarioDescription(scenarioId) {
$.ajax({
type: "GET",
url: 'https://localhost:44340/api/ScenarioDescriptors/GetScenarioDescriptions',
data: {scenarioId: scenarioId},
dataType: 'JSON',
success:function(data) {
$.each(data, function(key, val) {
console.log(val.scenarioDescription);
var descriptionText = val.scenarioDescription;
$('#descriptionDisplay').text(descriptionText); // This part isn't working correctly
})
}
});
}
尝试一下,使用.html
$("p").html("Hello <b>world</b>!");