Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Lagoanet

Erro em AJAX: retornando OK

Recommended Posts

ALGUÉM PODERIA ME DIZER SE HÁ ALGUM ERRO COM O CÓDIGO ABAIXO. NA MINHA OPINIÃO NÃO HÁ, MAS ESTÁ RETORNANDO "OK", ISSO MESMO, A STRING OK, E NÃO ESTÁ TUFANDO. NÃO SEI O PORQUE. ALGUÉM ME DARIA UMA LUZ.OBRIGADO.var req;function excluiNoticia(id){ url = 'exclui_not.php?id='+id; req = null; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = excNoticia; req.open("GET", url, true); req.send(null); } else if (window.ActiveXObject) { try { req = new ActiveXObject("Msxml2.XMLHTTP.4.0"); } catch(e){ try { req = new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { req = false; } } } } if (req) { req.onreadystatechange = excNoticia; req.open("GET", url, true); req.send(); } }}function excNoticia(){ if (req.readyState == 4) { if (req.status == 200) { if(req.statusText=="EXC"){//se tudo der certo na exclusão no script, ele retorna EXC para o JAVASCRIPT window.alert('Exclusão efetuada'); } else window.alert(req.statusText); } else { alert("Houve um problema ao obter os dados:\n" + req.statusText); } }}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Amigo, o alert que você está dando é apenas do status do ajax, não tem nada a ver com a parte em php... Basicamente ele sempre vai dar o alert OK porque ele achou o arquivo exclui_not.php.Se você quiser saber que ele realmente excluiu a notícia você deverá pegar o responseText do ajax e fazer um tratamento em cima deleValeu!!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.