I have a modal to which I pass a variable by javascript, the fact is that this variable has no way of contouring when it is empty or has data. The step of variable data-url to which I assign convenio.url_also does it well, since from the modal if I do an alert and have data shows them.
As if it's worth something, variable in origin comes from a json of a php file that I call with the ajax function, as the field is rich text, to remove the remains of html I apply this:
$data->url_aso=strip_tags($data->url_aso); //strip_tags elimina tags html de una cadena dada
$data->url_aso=str_replace ("p, li { white-space: pre-wrap; }" , "" , $data->url_aso ); //Esto lo hago ya que despues del strip_tags queda este resto y lo sustituyo por ""
This is the function where the variable happened.
$.each(objJsonConBus, function(f, convenio){
conv += '<li>'+
'<div '"data-url="'+convenio.url_aso +' "data-toggle="modal" data-target="#myModal" >'+
'<div class="card"><center><img class="img-responsive " src="'+convenio.base64_png+'" />'+
'<h5 CLASS="descuento ">'+subDescuento+'</h5></center></div></div>'+
'</li>';
});
This is the modal that receives the variable.
$('#myModal').on('show.bs.modal', function(e) {
var nameConv = $(e.relatedTarget).data('url');
if(nameConv!="")
{
alert(nameConv);
}
});
The way you tell me, always makes me the alert. Even if the alert shows me empty.
checking with typeof, if I put number it always tells me that it is false, if I put undefined, it also always tells me that it is false, it only tells me that it is true if I put string, that it always tells me that it is string, it gives me the impression that remains some kind of residue that does not appear in the alert but javaescript does not consider the variable as empty.