1
I’m having trouble filling a modal with data coming from an sql query.
I have a list of all the products. In this list I have a button that when clicked should open a modal with the product details.
Knob:
<button type="button" class="btn btn-primary btn-mini" data-toggle="modal" onclick="detalhesProduto(' + retorno[i].id + ')">+ Detalhes</button>
This button passes the product id to Function below:
function detalhesProduto(id) {
alert(id);
$('#myModal').modal('show');
}
In this case, I have another Function that connects and scans the bank , where I get the product id.
The way it is there, I click on the button opens a dialog with the id of the product selected, soon after opens the dialog, but I do not know how to fill it with the data... that in this case, if you filled at least the id I already had the rest.
My modal is like this:
<div class="modal fade bs-detalhes-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h5 class="modal-title" id="myModalLabel">Detalhes</h5>
</div>
<div class="modal-body" id="conteudoModal">
..............
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-mini" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
</div>
Could you give me a hand with that?
I didn’t understand this part: "The way it is there, I click on the button opens a dialog with the id of the selected product, then opens the dialog"
– Lucas
@Lucas is that when I click the button, I’m already getting the product ID ... and this ID I put on an Alert to see if it was changing as I click on another product from my list. That is, the dialog or modal... opens... just do not know how to take the product data and put in this modal.
– Marcia Pereira Reis
Um yes. Would have to do in Ajax
– Lucas
Got it, and how would I do it? I have an ajax that searches all my products and fills the list I mentioned. I took some examples on the net and could not succeed in filling the modal.
– Marcia Pereira Reis