2
I have a jquery function that mounts an html. It turns out there is a View with 4 tabs. When selecting a particular tab, the function is called and of course, load the dynamic html to assemble the page. What event do I do this for? I have this div:
<div id="agendamento">
</div>
In this div you should have all the html.
$('#agendamento').html(str);
The str variable is a concatenation of my HTML. See a part of it, just to illustrate:
var str = "";
//var resultado = jQuery.parseJSON();
$.ajax({
url: '/Agendamento/MontaAgendamento',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
//data: JSON.stringify({ }),
success: function (data) {
str += '<div id="FiltroPesquisa">';
str += '<table style="width: 100%;">';
str += '<tr>';
str += '<td class="Formatlabel"><strong>';
str += '<label id="lblCNPJ">CNPJ</label>';
str += '</strong></td>';
str += '<td class="auto-style25">';
str += '<input id="txtCNPJ" type="text"' + data.resultado[0].CNPJ + ' /></td>';
str += '</tr>';
str += '<tr>';
..............
$('#agendamento').html(str);
str = "";
I tried several ways and still nothing. Below one of the call forms:
<div id="tabs">
<ul>
<li><a href="#tabs-1">PDV</a></li>
<li><a href="#tabs-2">Eventos</a></li>
<li><a href="#tabs-3">Formulários</a></li>
<li><a href="#agendamento" onclick="return MontaAgendamento();">Agendamento</a></li>
</ul>
................
Is this it? I’m not getting the html. The way below I couldn’t assemble.
$('#agendamento a').click(function MontaAgendamento() {
var str = "";
//var resultado = jQuery.parseJSON();
$.ajax({
url: '/Agendamento/MontaAgendamento',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
//data: JSON.stringify({ }),
success: function (data) {
str += '<div id="FiltroPesquisa">';
str += '<table style="width: 100%;">';
str += '<tr>';
str += '<td class="Formatlabel"><strong>';
str += '<label id="lblCNPJ">CNPJ</label>';
str += '</strong></td>';
.................
$(this).attr('href').html(str);
str = "";
},
error: function (error) {
}
})
})
Friend what would be your tab? Would be a Tabs? Just take the Tab id and put in a . click your code..
– Ronny Amarante
That’s right, a Tab. But where do I put this onclick? Because I tried and I couldn’t assemble the HTML. That way it didn’t work: $('#scheduling').click.html(str);
– pnet
pnet, put the event in the element that will be clicked (be careful not to confuse the element where the user clicks with the element that will receive the data, the #scheduling). It looks like this : $("#element_clicked"). click(Function(){ .... here enters your ajax }); If your clicked element does not have an id, you will have to reference it with "$(this)".
– lfarroco
Dude, so I’m renaming the div’s ID, so I don’t confuse it with Tab’s name, which has the same name, just to do as Ifarroco says, right?
– pnet
Friend, put your function Montaagendamento();
– Joao Paulo
posted above in the post.
– pnet
I posted an answer. Test and if it doesn’t work press F12 and see in the Console if it shows any javascript error. I just edited it because it lacked close a function
– Joao Paulo