Trying to figure out how to update text in a Bootstrap 3 Popover using JavaScript. I suspect my use of Promises is incorrect because the text only appears in the popover after clicking it twice.
The JavaScript code involves calling a local C# Proxy. Here's an excerpt from the setup of the popover:
$(function () {
$('#session-cookie-showcase').popover({
html: true
});
$('#session-cookie-showcase').on('show.bs.popover', function () {
Promise.resolve(getSessionCookieAsString()).then(function (value) {
$('#session-cookie-showcase').data('bs.popover').config.content = value;
})
})
})
This is how the ajax call is structured:
async function getSessionCookieAsString(callback) {
return $.ajax({
type: "GET",
url: AppName + '/api/omitted/hentSessionCookieSomTekst',
dataType: "json",
contentType: "application/json",
success: ((result) => function (result) { return result }),
error: ((XMLHttpRequest, textStatus, errorThrown) =>
handleWebserviceCallError(XMLHttpRequest, textStatus, errorThrown, false))
});
}
And here's a snippet of the C# proxy code:
[HttpGet("hentSessionCookieSomTekst")]
public string HentSessionCookieSomTekst()
{
string userKey = _configuration.GetSection("SessionKeys:User").Value;
if (!string.IsNullOrEmpty(userKey))
{
BrugerObjekt bruger = HttpContext.Session.Get<BrugerObjekt>(userKey);
return JsonConvert.SerializeObject(bruger.ToString('n'));
}
else
{
return JsonConvert.SerializeObject("NULL");
}
}
In summary, the call works but only on the second click. Is there a way to make the text load in on the first click or resolve this issue differently?