1
I have a simple html file and want to ghettarda it in a variable to use, I made the get so:
let popup = '';
$.get( "popup.html", function( data ) {
// the contents is now in the variable data
console.log("data"+data);
popup = data;
});
console.log("popup"+popup);
However not saving in popup, the log is:
popup
(index):247 data<p style="font-weight: bold;font-size: 16px" id="nome">a</p>
<div class="dropdown-divider w-50 mx-auto "></div>
<p id="endereco">c</p>
<p id="tel">dc</p>
<p id="email">ca</p>
data has my html, but not popup, I’m doing something wrong?
I’m not sure, but I think your problem is Let. Maybe it doesn’t allow you to set the value in the context below. You may be understanding that the popup is a new variable
– DiegoSantos
Or also, if the request is asynchronous, this behavior is normal. Understand that the value assignment, in this case, can occur after the console.log
– DiegoSantos
This console.log that you showed in the question is the
console.log("data"+data);
orconsole.log("popup"+popup);
?– Sam
the 2, the popup came before
– Igor Oliveira
It is because the ajax is asynchronous... the
popup
will only receive the value within the get function– Sam
I get it, you can’t make this signature ?
– Igor Oliveira