0
Code in index.php
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title></title>
<script type="text/javascript" src="jquery-2.2.3.min.js"></script>
<script>
function carregaPagina(item, pai, filho, url) {
var caminho = item != null ? $(item).attr('data-click') : url;
if (item != null) {
if ($(item).attr('data-json') != null) {
$('#' + $(item).attr('local-json')).html($(item).attr('data-json'));
}
}
if (pai != "" && pai != null) {
$('#' + pai).slideToggle(1000);
}
$.ajax({
url: caminho,
cache: false,
dataType: "html",
success: function (data) {
$('#' + filho).slideToggle(0);
$('#' + filho).html(data);
$('#' + filho).slideToggle(1000, function () {
if (typeof completaLoad !== 'undefined' && $.isFunction(completaLoad)) {
completaLoad();
}
if ($('#' + pai).css('display') !== 'none') {
$('#' + pai).slideToggle(0);
}
});
}
});
return false;
}
$(document).ready(function () {
$(document).on('click', '.grid', function (e) {
if (e.handled !== true) {
carregaPagina(this, 'TelaConsulta', 'TelaEditar', null);
e.handled = true;
}
return false;
});
});
</script>
<style>
.grid, .item, .btnVoltar {
cursor: pointer;
}
#TelaConsulta {
background-color: #81BEF7;
}
#TelaEditar {
background-color: #58FAAC;
}
#TelaItem {
background-color: #F6D8CE;
}
</style>
</head>
<body>
<div id="TelaConsulta">
<ul>
<li><span class="grid" data-click="editar.php?id=25">Editar</span></li>
<li><span class="grid" data-click="editar.php?id=35">Editar</span></li>
</ul>
</div>
<div id="TelaEditar">
</div>
<div id="TelaItem">
</div>
</body>
</html>
Code in edit.php
<script>
$(document).ready(function () {
$(document).on('click', '.item', function (e) {
if (e.handled !== true) {
debugger;
var url = 'item.php?id=<?php echo $_GET['id']; ?>';
carregaPagina(null, 'TelaEditar', 'TelaItem', url);
e.handled = true;
}
return false;
});
$('#TelaEditar .btnVoltar').click(function () {
$('#TelaEditar').slideToggle(1000, function () {
$('#TelaConsulta').slideToggle(1000);
$('#TelaEditar').empty();
$('#TelaEditar').removeAttr('style');
});
return false;
});
});
</script>
Código: <?php
echo $_GET['id'];
?><br><br>
<span class="item">Item</span><br><br>
<span class="btnVoltar">Voltar</span>
Code in item.php
<script>
$(document).ready(function () {
$('#TelaItem .btnVoltar').click(function () {
$('#TelaItem').slideToggle(1000, function () {
$('#TelaEditar').slideToggle(1000);
$('#TelaItem').empty();
$('#TelaItem').removeAttr('style');
});
return false;
});
debugger;
});
</script>
Código: <?php echo $_GET['id']; ?><br><br>
<span class="btnVoltar">Voltar</span>
In the index.php file click on the first Edit.
On the edit screen it shows the Id 25, insert a Debugger on the Item button of the edit.php file note that when you click the button it opens the VM108.
I inserted a Debugger in the item.php file note that it opens VM119 and returns Id 25.
Then click the back button of the item.php file and then click the back button of the edit.php. In the index.php file click the 2nd Edit, when displaying the edit.php file it returns Id 35.
When you click the Item button in the edit.php file note that it reopens VM108.
When displaying the contents of the.php item note that it opens VM141 and returns Id 25.
This is my question, only the first time it returns the correct Id, in all other attempts it returns the Id of the 1st access.
Link simulation: link
Post the event statement click that you do to call this function.
– Duque
Do a Jsfiddle and simulate the difficulty as you are still confused to understand.
– Duque
I improved the text to explain the situation
– Cristiano Ávila Salomão
I couldn’t find where you call this method loadPagina() passing the parameters to him.
– Duque
I added an example and the function that calls the chargePagina()
– Cristiano Ávila Salomão
Friend, your code is a little problematic. You are using onclick() in the tag, but at the same time use Jquery(). I will post the possible solution.
– Duque
What is the return of chargePagina? You are not clearing the click event by uploading a new page, the event will remain the same until you clear the event. From what I imagine this loadPagina is coming a JS together that you want to use in place of the old one, right?
– Gabriel Katakura
carregaPagina is returning HTML and JS. Exactly, I even put nocache on the page, but I was not successful. How should I proceed to clear the event?
– Cristiano Ávila Salomão