joaocasta Posted August 17, 2012 at 11:31 AM Report Share #472563 Posted August 17, 2012 at 11:31 AM (edited) Boas tardes.... tenho aqui este codigo: <script type="text/javascript"> $(document).ready(function(){ //Get the input data using the post method when Push into mysql is clicked .. we pull it using the id fields of ID, Name and Email respectively... $("#insert").click(function(){ //Get values of the input fields and store it into the variables. var ID=$("#ID").val(); var Name=$("#Name").val(); var Email=$("#Email").val(); //use the $.post() method to call insert.php file.. this is the ajax request $.post('insert.php', {ID: ID, Name: Name, Email: Email}, function(data){ $("#message").html(data); $("#message").hide(); $("#message").fadeIn(1500); //Fade in the data given by the insert.php file }); return false; }); }); </script> e queria adicionar este código, para mostrar a imagem de loading enquanto insere na bd: <script> $(document).ready(function() { $.ajaxSetup({ cache: false }); $("#placeholder").load("loading.gif"); var refreshId = setInterval(function() { $("#placeholder").load("loading.gif"); }, 500); }); </script> Edited August 17, 2012 at 11:36 AM by joaocasta Link to comment Share on other sites More sharing options...
taviroquai Posted August 17, 2012 at 11:53 AM Report Share #472567 Posted August 17, 2012 at 11:53 AM Viva, Já que usas jQuery, o melhor método é usar .ajaxStart() e .ajaxStop(). Lê http://api.jquery.com/ajaxStart/ Link to comment Share on other sites More sharing options...
joaocasta Posted August 17, 2012 at 12:43 PM Author Report Share #472573 Posted August 17, 2012 at 12:43 PM (edited) Boas taviroquai, já li esse método e pareceu-me bom para o que quero. Encontrei isto: $("div#loading").ajaxStart(function(){ $(this).html('<img src="loading.gif"'); }); mas como poderei adiciona-lo neste codigo: <script type="text/javascript"> $(document).ready(function(){ //Get the input data using the post method when Push into mysql is clicked .. we pull it using the id fields of ID, Name and Email respectively... $("#insert").click(function(){ //Get values of the input fields and store it into the variables. var ID=$("#ID").val(); var Name=$("#Name").val(); var Email=$("#Email").val(); //use the $.post() method to call insert.php file.. this is the ajax request $.post('insert.php', {ID: ID, Name: Name, Email: Email}, function(data){ $("#message").html(data); $("#message").hide(); $("#message").fadeIn(1500); //Fade in the data given by the insert.php file }); return false; }); }); </script> Não sei bem onde o colocar. mas acho que seja assim: //use the $.post() method to call insert.php file.. this is the ajax request $.post('insert.php', {ID: ID, Name: Name, Email: Email}, function(data){ $("#message").html(data); $("#message").hide(); $("#message").fadeIn(1500); //Fade in the data given by the insert.php file $("div#loading").ajaxStart(function(){ $(this).html('<img src="loading.gif"'); }); será assim? poderão dar-me alguma dica/sugestao de como tentar fazer? Edited August 17, 2012 at 12:45 PM by joaocasta Link to comment Share on other sites More sharing options...
pikax Posted August 17, 2012 at 01:16 PM Report Share #472578 Posted August 17, 2012 at 01:16 PM Primeiro falta-te fechar uma chaveta. Diz-me o que percebes do codigo e o que nao percebes? Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
joaocasta Posted August 17, 2012 at 01:25 PM Author Report Share #472580 Posted August 17, 2012 at 01:25 PM //use the $.post() method to call insert.php file.. this is the ajax request $.post('insert.php', {ID: ID, Name: Name, Email: Email}, function(data){ $("#message").html(data); $("#message").hide(); $("#message").fadeIn(1500); //Fade in the data given by the insert.php file $("div#loading").ajaxStart(function(){ $(this).html('<img src="loading.gif"'); }); }); entao vamos lá separar isto: $.post('insert.php', {ID: ID, Name: Name, Email: Email}, Aqui é chamada a página insert.php pelo "$.post" que irá inserir na base de dados com os dados que estão dentro de chaveta, acho eu. function(data){ $("#message").html(data); $("#message").hide(); $("#message").fadeIn(1500); //Fade in the data given by the insert.php file Aqui fiquei sem perceber nada.... tentei interpretar mas nada. $("div#loading").ajaxStart(function(){ $(this).html('<img src="loading.gif"'); }); }); E aqui é chamada a imagem loading.gif enquanto está a inserir na base de dados. mas acho que coloquei no sitio errado. Link to comment Share on other sites More sharing options...
pikax Posted August 17, 2012 at 01:32 PM Report Share #472582 Posted August 17, 2012 at 01:32 PM entao vamos lá separar isto: $.post('insert.php', {ID: ID, Name: Name, Email: Email}, Aqui é chamada a página insert.php pelo "$.post" que irá inserir na base de dados com os dados que estão dentro de chaveta, acho eu. Isto e' igual a teres uma form: <form method="POST"> <input name="ID"> <input name="Name"> <input name="Email"> </form> function(data){ $("#message").html(data); $("#message").hide(); $("#message").fadeIn(1500); //Fade in the data given by the insert.php file Aqui fiquei sem perceber nada.... tentei interpretar mas nada. Ja' estudaste o jquery??? Basicamente isso vai buscar o elemento com o id="message" e vai por o "valor" data que foi retornado 'a chamada de cima. depois vai esconder essa informacao e vai fazer um fadeIn de 1.5s. $("div#loading").ajaxStart(function(){ $(this).html('<img src="loading.gif"'); }); }); E aqui é chamada a imagem loading.gif enquanto está a inserir na base de dados. mas acho que coloquei no sitio errado. ???? Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
joaocasta Posted August 17, 2012 at 01:45 PM Author Report Share #472585 Posted August 17, 2012 at 01:45 PM onde tenho de colocar ?? $("div#loading").ajaxStart(function(){ $(this).html('<img src="loading.gif"'); }); }); Link to comment Share on other sites More sharing options...
pikax Posted August 17, 2012 at 01:51 PM Report Share #472587 Posted August 17, 2012 at 01:51 PM onde tenho de colocar ?? $("div#loading").ajaxStart(function(){ $(this).html('<img src="loading.gif"'); }); }); Para mim esse codigo nao tem nexo estar junto ao codigo de cima(pelo o menos para mim), tens que aprender a trabalhar com o jquery, falo por mim, mas eu nao vou estar a ensinar-te a programar com jquey aqui no forum, para mais quando tens N de tuts por ai, estuda e percebe o que faz cada funcao, cria umas funcoes e brinca um pouco, quando tiveres duvidas ajudo-te. Mas agora teres duvidas por nao teres estudado quando deverias de ter estudado isso e' que e' um bocado chato para mim. Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
joaocasta Posted August 17, 2012 at 03:58 PM Author Report Share #472640 Posted August 17, 2012 at 03:58 PM (edited) bem fiz outra pagina e uma nova tabela pra testar: <html> <head> <title>zwaroop's home</title> <!-- include jquery library file--> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js%22></script> <!-- The ajax/jquery stuff --> <script type="text/javascript"> $(document).ready(function(){ //Get the input data using the post method when Push into mysql is clicked .. we pull it using the id fields of ID, Name and Email respectively... $("#insert").click(function(){ //Get values of the input fields and store it into the variables. var Name=$("#Name").val(); var Email=$("#Email").val(); //use the $.post() method to call insert.php file.. this is the ajax request $.post('data.php', {eame: name, email: email}, function(data){ $("#message").html(data); $("#message").hide(); $("#message").fadeIn(1500); //Fade in the data given by the insert.php file $("#message").html('Submitting your Request.<img src="ajax.gif" />'); }); return false; }); }); </script> </head> <body> <form action="" method="post"> <label>Name: </label> <input id="name" type="text" /> <label>E-Mail: </label> <input id="email" type="text" /> <input type="submit" id="insert" value="Register"/> </form> <!-- For displaying a message --> <div id="message"></div> </body> </html> Mas quando carrego no botão registar, nao insere na base de dados nem aparece o loading.gif. Edited August 17, 2012 at 03:59 PM by joaocasta Link to comment Share on other sites More sharing options...
pikax Posted August 17, 2012 at 04:00 PM Report Share #472641 Posted August 17, 2012 at 04:00 PM nao deveria de ser assim: //$.post('data.php', {eame: name, email: email}, $.post('data.php', {name: Name, email: Email}, //... Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
joaocasta Posted August 17, 2012 at 04:03 PM Author Report Share #472642 Posted August 17, 2012 at 04:03 PM (edited) como posso fazer a confirmaçao pra nao enviar dados em branco e para nao enviar varias vezes para a base de dados se carregar varias vezes. e agora aparece sempre a imagem em loading.... Edited August 17, 2012 at 04:04 PM by joaocasta Link to comment Share on other sites More sharing options...
pikax Posted August 17, 2012 at 04:06 PM Report Share #472644 Posted August 17, 2012 at 04:06 PM como posso fazer a confirmaçao pra nao enviar dados em branco e para nao enviar varias vezes para a base de dados se carregar varias vezes. e agora aparece sempre a imagem em loading.... Conforme, podes fazer em PHP(e' sempre recomendado!!) e no Javascript, verificas if(Email.Lenght==0 || Email == "" ) return; ... e por ai adiante. Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
joaocasta Posted August 17, 2012 at 04:08 PM Author Report Share #472645 Posted August 17, 2012 at 04:08 PM e o porque de estar sempre em loading? Link to comment Share on other sites More sharing options...
pikax Posted August 17, 2012 at 04:11 PM Report Share #472647 Posted August 17, 2012 at 04:11 PM e o porque de estar sempre em loading? como assim? Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
joaocasta Posted August 17, 2012 at 04:13 PM Author Report Share #472648 Posted August 17, 2012 at 04:13 PM depois de eu fazer submit a imagem de loading esta sempre lá.... Link to comment Share on other sites More sharing options...
pikax Posted August 17, 2012 at 04:14 PM Report Share #472649 Posted August 17, 2012 at 04:14 PM (edited) $("#message").html(data); $("#message").hide(); $("#message").fadeIn(1500); //Fade in the data given by the insert.php file $("#message").html('Submitting your Request.<img src="ajax.gif" />'); Explica-me este codigo, se conseguires perceber o codigo, descobres logo o problema Edited August 17, 2012 at 04:14 PM by pikax Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
joaocasta Posted August 17, 2012 at 04:26 PM Author Report Share #472650 Posted August 17, 2012 at 04:26 PM hide() esconde e o fadeIn determina o tempo que fica a mostrar. mas por acaso acho que a imagem está ali mal. e nao insere na base de dados ou quer dizer insere mas em branco e em preencho os inputs. nao percebo. Link to comment Share on other sites More sharing options...
pikax Posted August 17, 2012 at 04:29 PM Report Share #472651 Posted August 17, 2012 at 04:29 PM hide() esconde e o fadeIn determina o tempo que fica a mostrar. mas por acaso acho que a imagem está ali mal. e nao insere na base de dados ou quer dizer insere mas em branco e em preencho os inputs. nao percebo. O mais importante nao falaste, olha a ordem disto: $("#message").html(data); //..... $("#message").html('Submitting your Request.<img src="ajax.gif" />'); Nao parece que algo esta errado? Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
joaocasta Posted August 17, 2012 at 04:34 PM Author Report Share #472652 Posted August 17, 2012 at 04:34 PM $("#message").html(data); //..... $("#message").html('Submitting your Request.<img src="ajax.gif" />'); a imagem tem q ser antes do hide acho... Link to comment Share on other sites More sharing options...
pikax Posted August 17, 2012 at 04:34 PM Report Share #472653 Posted August 17, 2012 at 04:34 PM a imagem tem que ser pelo o menos antes do $("#message").html(data); Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now