[Cascavel-pm] Redirecionamento com Ajax
Alex Falcão
alexjfalcao em universia.com.br
Quinta Setembro 13 11:38:25 PDT 2007
Senhores,
voces me ajudaram muito a achar o caminho, o código ficou assim.
Obrigado pela colaboração
<code>
use strict;
use CGI;
use CGI::Ajax;
my $cgi = new CGI;
my $ex_verifica = sub {
my $nome = shift || undef;
if ($nome eq 'alex') {
return ('alex', 0);
} else {
return ('', 1);
}
};
my $inicial = sub {
my $html =<<EOF;
<html>
<head>
</head>
<body>
DIGITE SEU NOME: <input type="text" name="nome" id="nome"><br>
<input value="envia" type="button" id="bt"
onClick="verifica(['nome'],[js_func], 'POST');"><br>
<div id="div_msg"></div>
<script language="Javascript\">
function js_func() {
var input1 = arguments[0];
var input2 = arguments[1];
document.getElementById('div_msg').innerHTML = input1;
if (input2 == 1) {
window.location="x.pl";
}
}
</script>
</body>
</html>
EOF
return $html;
};
my $pjx = CGI::Ajax->new( 'verifica' => $ex_verifica);
print $pjx->build_html($cgi,$inicial);
</code>
Em 13/09/07, Thomas Britis <thomas em tcnet.com.br> escreveu:
>
> Penso que você poderia setar um timer via javascript redirecionando o
> usuário para uma página gravada numa váriavel (somente se a variável
> existir). E seu return seria um javascript setando a variável.
> Mas, é só um palpite.
>
> Alex Falcão wrote:
> > Oi Alceu,
> >
> > muito obrigado, mas eu já havia tentado com javascript, talvez tenha
> > feito algo errado, pois não funcionou. Segue o código.
> >
> > Se mais alguem tiver algum palpite, agradeço
> >
> > Abraço a todos
> >
> > <code>
> > use strict;
> > use CGI;
> > use CGI::Ajax;
> >
> > my $cgi = new CGI;
> >
> > my $ex_verifica = sub {
> > my $nome = shift || undef;
> >
> > if ($nome eq 'alex') {
> > return "OI $nome";
> > } else {
> > return "<script
> > language=\"Javascript\">window.location=\"x.pl\"</script>";
> > }
> > };
> >
> > my $inicial = sub {
> >
> > my $html =<<EOF;
> > <html>
> > <head>
> > </head>
> > <body>
> > DIGITE SEU NOME: <input type="text" name="nome" id="nome"><br>
> > <input value="envia" type="button" id="bt"
> > onClick="verifica(['nome'],['div_msg']);"><br>
> > <div id="div_msg"></div>
> > </body>
> > </html>
> > EOF
> >
> > return $html;
> > };
> >
> > my $pjx = CGI::Ajax->new( 'verifica' => $ex_verifica);
> > print $pjx->build_html($cgi,$inicial);
> > </code>
> >
> > Em 13/09/07, *Alceu Rodrigues de Freitas Junior *
> > <glasswalk3r em hotmail.com <mailto:glasswalk3r em hotmail.com>> escreveu:
> >
> > Oi Alex,
> >
> > Seu script Ajax está alterando apenas uma parte da página? Se for,
> > acho que não dá para utilizar meta tags de refresh. Não sei se você
> > consegue fazer isso via cabeçalho HTTP.
> >
> > O que você poderia tentar fazer é enviar via Ajax um controle em
> > Javascript mesmo para redirecionar o usuário depois de n segundos.
> >
> > []'s
> > Alceu
> >
> >
> ------------------------------------------------------------------------
> > Date: Thu, 13 Sep 2007 00:50:39 -0300
> > From: alexjfalcao em universia.com.br
> > <mailto:alexjfalcao em universia.com.br>
> > To: cascavel-pm em pm.org <mailto:cascavel-pm em pm.org>
> > Subject: [Cascavel-pm] Redirecionamento com Ajax
> >
> >
> > Salve monges,
> >
> > estou fazendo algumas coisas simples com o CGI::Ajax, mas
> > estou tendo um problema.
> > No codigo abaixo, quando digito o nome alex, mostro a
> > mensagem, ai foi facil.
> > Mas o que eu preciso fazer e redirecionar para outra pagina
> > quando digito errado, no exemplo, simplesmente mostrei o texto,
> > mas precisava redirecionar.
> >
> > Alguem tem alguma ideia?
> >
> > Obrigado a todos
> >
> > <code>
> > use strict;
> > use CGI;
> > use CGI::Ajax;
> >
> > my $cgi = new CGI;
> >
> > my $ex_verifica = sub {
> > my $nome = shift || undef;
> >
> > if ($nome eq 'alex') {
> > return "OI $nome";
> > } else {
> > return "DIRECIONA PARA x.pl?n=$nome";
> > }
> > };
> >
> > my $inicial = sub {
> >
> > my $html =<<EOF;
> > <html>
> > <head></head>
> > <body>
> > DIGITE SEU NOME: <input type="text" name="nome"
> > id="nome"><br>
> > <input value="envia" type="button" id="bt"
> > onClick="verifica(['nome'],['div_msg']);"><br>
> > <div id="div_msg"></div>
> > </body>
> > </html>
> > EOF
> >
> > return $html;
> > };
> >
> > my $pjx = CGI::Ajax->new( 'verifica' => $ex_verifica);
> > print $pjx->build_html($cgi,$inicial); # this outputs the html
> > for the page
> >
> > </code>
> >
> > --
> >
> > ______________________________
> > Alex Falcão
> >
> >
> >
> ------------------------------------------------------------------------
> > Get news, entertainment and everything you care about at Live.com
> > <http://Live.com>. Check it out! <
> http://www.live.com/getstarted.aspx+>
> >
> > _______________________________________________
> > Cascavel-pm mailing list
> > Cascavel-pm em pm.org <mailto:Cascavel-pm em pm.org>
> > http://mail.pm.org/mailman/listinfo/cascavel-pm
> >
> >
> >
> >
> > --
> >
> > ______________________________
> > Alex Falcão
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Cascavel-pm mailing list
> > Cascavel-pm em pm.org
> > http://mail.pm.org/mailman/listinfo/cascavel-pm
>
> --
> Thomas Storino Britis
> TCNet Informatica e Telecomunicacoes LTDA
> _______________________________________________
> Cascavel-pm mailing list
> Cascavel-pm em pm.org
> http://mail.pm.org/mailman/listinfo/cascavel-pm
>
--
______________________________
Alex Falcão
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: http://mail.pm.org/pipermail/cascavel-pm/attachments/20070913/9ccd99bc/attachment-0001.html
Mais detalhes sobre a lista de discussão Cascavel-pm