Writing some JavaScript to update some text in a Bootstrap 3 Popover. I'm probably not using Promises right, but I want the text to appear in the popover the first time I click, not when I've clicked it twice.
The Javascript calls a local Proxy written in C#. The JavaScript for the setup of the popover itself looks like this:
$(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;
})
})
})
The ajax call looks like this:
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 finally the C# proxy looks like this:
[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");
}
}
So to reiterate; The call works. But it only works on the second click of my element, never on the first. Can I somehow make the text load in whenever it is deemed ready instead of having to click again or fix this some other way?