Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá.. estou com duvida a respeito do cadastro , ele esta efetuando certinho e talz.. só que quero que apareca o loading e nao aparece de jeito nenhum, peguei esse codigo aqui do forum mesmo
script.js
function ajax() {};ajax.prototype.iniciar = function() { try{ this.xmlhttp = new XMLHttpRequest(); }catch(ee){ try{ this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try{ this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }catch(E){ this.xmlhttp = false; } } } return true;}ajax.prototype.ocupado = function() { estadoAtual = this.xmlhttp.readyState; return (estadoAtual && (estadoAtual < 4));}ajax.prototype.processa = function() { if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) { return true; }}ajax.prototype.enviar = function(url, metodo, modo) { if (!this.xmlhttp) { this.iniciar(); } if (!this.ocupado()) { if(metodo == "GET") { this.xmlhttp.open("GET", url, modo); this.xmlhttp.send(null); } else { this.xmlhttp.open("POST", url, modo); this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); this.xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate"); this.xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0"); this.xmlhttp.setRequestHeader("Pragma", "no-cache"); this.xmlhttp.send(url); } if (this.processa) { return unescape(this.xmlhttp.responseText.replace(/\+/g," ")); } } return false;}function cadastrar() { nome1 = document.getElementById('nome').value; nome = escape(nome1); usuario1 = document.getElementById('usuario').value; usuario = escape(usuario1); senha1 = document.getElementById('senha').value; senha = escape(senha1); xmlhttp = new ajax(); id = xmlhttp.enviar('cadastro.php?acao=cadastrar&nome='+ nome + '&usuario=' + usuario + '&senha='+ senha, "POST", false); //manda adicionar document.getElementById('nome').value=""; document.getElementById('usuario').value=""; document.getElementById('senha').value="";}Nesse codigo ai em cima houve algumas coisas que eu nao intendi, como ajax.prototype.xxxx pra que serve o prototype na frente? essas funcoes com prototype na frente sempre serao iniciadas qd o ajax for criado? para colocar o loading nao bastaria colocar somente isso no function cadastrar: if (xmlhttp.ocupado==true) //Mostraria o carregando..
vou colocar as otras paginas agora:
index.php
<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><script language="javascript" src="script.js"></script><style>* { text-align: center;}h1 {font-family: Verdana, Tahoma, Arial, Trebuchet MS, Sans-Serif, Georgia, Courier, Times New Roman, Serif; font-size: 20px; font-weight: bold;}th { background: #f3f3f3; height: 30px;}td { background: #f9f9f9; height: 20px;}</style></head><body><table align="center" cellspacing="0"> <tr> <tr><td width="70"> </td><td width="70"> </td></tr> <tr><td width="200">Nome Completo: </td><td><input name="nome" type="text" id="nome" /></td></tr> <tr><td width="200">Usuario</td><td><input name="usuario" type="text" id="usuario" /></td></tr> <tr><td width="200">Senha</td><td><input name="senha" type="text" id="senha"/></td></tr><tr><td width="179"> <input name="button" type="button" onclick="cadastrar();" value="Cadastrar"/></td></tr> </tr> <tr></table><br><div id="carregando" name="carregando"></div></body></html>
cadastro.php
<?php//conecta ao banco de dadosmysql_connect("localhost", "xxx", "yyy");mysql_select_db("tuto");//essa function eu coloquei para retornar o id e inserir na tabela, ela eh desnecessaria para o funcionamento...coloquei porq no meu tava xDfunction autoindex($tb){ $query = mysql_query('SHOW TABLE STATUS LIKE "' . $tb . '"'); $data = mysql_fetch_array($query); return $data['Auto_increment'];}switch ($_REQUEST['acao']) {//se acao = add entao adicionarcase 'cadastrar' : $valor = urldecode($_REQUEST['nome']); //Filtra os acentos $valor2 = urldecode($_REQUEST['usuario']); $valor3 = urldecode($_REQUEST['senha']); echo autoindex("cadajax"); mysql_query("INSERT INTO cadajax VALUES('','$valor','$valor2','$valor3')"); break;}?>Carregando comentários...