Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Bom dia a toda galera ninja em JS, tudo bem com vocês?
Estou com um problema que está me deixando de cabelo em pé, eu inserir o código abaixo em meu projeto mas ao executar o mesmo meu elemento accordion e 02 modais parou de funcionar, será que alguém pode me ajudar ou me dar a direção do caminho correto para que o mesmo volte a funcionar.
Segue código abaixo,.
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","filtro.php?filtro="+str,true);
xmlhttp.send();
}
}Segue o código do Accordion Abaixo:
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].onclick = function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight){
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + 'px';
}
}
}
Código do Modal
//AJAX PARA O BOTÃO INSERIR
$(document).ready(function() {
/// Quando usuário clicar em salvar será feito todos os passo abaixo
$('#btnsalvar').click(function() {
var dados = $('#frmcadastro').serialize();
$.ajax({
type: 'POST',
//dataType: 'json',
url: 'insert.php',
async: true,
data: dados,
success: function(response) {
location.reload();
}
});
return false;
});
//MODAL DA JANELA DE INSERIR
$("a[rel=adicionar]").click(function(ev) {
ev.preventDefault();
var id = $(this).attr("href");
var alturaTela = $(document).height();
var larguraTela = $(window).width();
//colocando o fundo preto
$('.mascara').css({'width': larguraTela, 'height': alturaTela});
$('.mascara').fadeIn(1000);
$('.mascara').fadeTo("slow", 0.8);
var left = ($(window).width() / 2) - ($(id).width() / 2);
var top = ($(window).height() / 2) - ($(id).height() / 2);
$(id).css({'top': top, 'left': left});
$(id).show();
});
$(".mascara").click(function() {
$(this).hide();
$(".window").hide();
});
$('.fechar').click(function(ev) {
ev.preventDefault();
$(".mascara").hide();
$(".window").hide();
});
});//AJAX DO EDITAR E MODAL
$("a[rel=modal]").click(function(ev) {
ev.preventDefault();
var id = $(this).attr("href");
var alturaTela = $(document).height();
var larguraTela = $(window).width();
$('.mascarae').css({'width': larguraTela, 'height': alturaTela});
$('.mascarae').fadeIn(1000);
$('.mascarae').fadeTo("slow", 0.8);
var left = ($(window).width() / 2) - ($(id).width() / 2);
var top = ($(window).height() / 2) - ($(id).height() / 2);
$(id).css({'top': top, 'left': left});
$(id).show();
});
$(".mascarae").click(function() {
$(this).hide();
$(".windowe").hide();
});
$('.fechar').click(function(ev) {
ev.preventDefault();
$(".mascarae").hide();
$(".windowe").hide();
});// AJAX PARA EXCLUSÃO DE REGISTROS
$(document).ready(function() {
$('.delete').click(function(){
var element = $(this);
var del_id = element.attr('id');
var info = 'id=' + del_id;
if(confirm('Você deseja excluir esse registro?')){
$.ajax({
type: 'GET',
url: 'delete.php',
async: true,
data: info,
success: function(response) {
location.reload();
}
});
//$(this).parents(".accordion").animate({ backgroundColor: "red" }, "slow")
//.animate({ opacity: "hide" }, "slow");
}
return false;
});
});/AJAX PARA SELECIONAR O TIPO DE FILTRO/
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","filtro.php?filtro="+str,true);
xmlhttp.send();
}
}
Será que isso ajuda?E ai pessoal alguém pode me dar um feedback referente a postagem acima?
Se estás a usar jQuery, porque não usas a função ajax para fazer o pedido?
Mais uma nota: tens dois eventos DOM ready no teu código, sendo que podes colocar tudo num só event handler.
Como fazer isso?
Em princípio este código não estará relacionado com o modal e accordion. Verfica se há erros na consola do browser (CTRL+Shift+J no Chrome).