Feed Textarea with bank field

Asked

Viewed 249 times

0

I’m trying to do this: I need to feed a textarea, every minute, with the result of the query below:

$consulta = OCIParse($ora_conexao,"Select
                                   pcn.romaneio       Romaneio
                                   from
                                   PCN_ROMANEIO_RESUMO    pcn
                                   Where
                                   pcn.status = "A"
                                   order by 1");

OCIDefineByName($consulta,"ROMANEIO",$romaneio);

OCIExecute($consulta);

while (OCIFetch($consulta)){

"exibir na textarea"

}

I tried putting in the meta-tag a refresh every minute, but the result does not appear in textarea. On the last attempt by placing inside the while a tag <textarea> he created one for each result....

PS: This page will be displayed on a collector, which has IE 6 only....

There’s a way to do it?

What I tried:

HTML

<!DOCTYPE html>
<html lang="pt-br">
<head>
<script type="text/javascript" src="js/PesquisaRomaneio.js"></script>
<link rel="stylesheet" href="js/styles.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>::: SIG - Sistemas de Informações Gerenciais - Peccin S.A.:::</title>

<body>
<form id="cadastro" name="cadastro" method="POST" action="login.php" autocomplete="off">
  <fieldset>
    <legend><b><center><img src="images/logo.png" width="55" height="22"/><br>Coleta de dados - WMS:</center></b></legend>
    <br>ROMANEIOS PARA CONFERÊNCIA:<br>
    <input type="text" id="busca" onClick="buscarRomaneio()" autofocus />
    <div id="resultado"></div>
    <br /><br />
    <div id="conteudo"></div>

     <input type="button" onclick = "location.href='/coleta/Separacao';" value="SEPARAÇÃO" style="height:35px; width:80px;">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
     <input type="button" onclick = "location.href='/coleta/Conferencia';" value="CONFERÊNCIA" style="height:35px; width:80px;">
  </fieldset>
</form>
</body>
</html>

Pesquisaromaneio.js

var req;

// FUNÇÃO PARA BUSCA MOTORISTA
function buscarRomaneio() {

// Verificando Browser
if(window.XMLHttpRequest) {
   req = new XMLHttpRequest();
}
else if(window.ActiveXObject) {
   req = new ActiveXObject("Microsoft.XMLHTTP");
}

// Arquivo PHP juntamente com o valor digitado no campo (método GET)
//var url = "PesquisaUsuario_Busca.php?cracha="+cracha;

// Chamada do método open para processar a requisição
//req.open("Get", url, true);

// Quando o objeto recebe o retorno, chamamos a seguinte função;
req.onreadystatechange = function() {

    // Exibe a mensagem "Buscando MOtorista..." enquanto carrega
    if(req.readyState == 1) {
        document.getElementById('resultado').innerHTML = 'Buscando Usuário...';
    }

    // Verifica se o Ajax realizou todas as operações corretamente
    if(req.readyState == 4 && req.status == 200) {

    // Resposta retornada pelo busca.php
    var resposta = req.responseText;

    // Abaixo colocamos a(s) resposta(s) na div resultado
    document.getElementById('resultado').innerHTML = resposta;
    }
}
//req.send(null);
}

Researchromaneio.php

<?php
// Dados do banco
include 'config.php';

//Inicia a consulta ao banco Oracle, com os dados informados pelo cliente.
$consulta2 = OCIParse($ora_conexao,"select * from PCN_ROMANEIO_COLETA");

//aqui prepara a consulta, nome da coluna e a variavel retorno da consulta
OCIDefineByName($consulta2,"ROMANEIO",$v_romaneio);

// executa a consulta
OCIExecute($consulta2);

/* Gera um arry com o resultado para mandar para o Ajax.
*/
while (OCIFetch($consulta2)){
    echo "<td>" . $v_romaneio . "</td><br />";
}


OCIFreeStatement($consulta2);

// Acentuação
header("Content-Type: text/html; charset=ISO-8859-1",true);
?>
  • put your Javascript and HTML there so we can better understand what you are doing.

  • Apparently all right, the problem would only be to do the requisicao every 1 minute?

  • The code is a little messy, I admit, but that’s basically what it would be like to requisition every minute. It gave an XML error in the execution, but fixed and opened the value on the page, now only missing the minute in minute... Thanks

  • Diego deleted the other question about ajax why? I was answering :/

  • Sorry, I’ll reopen it. I did not solve the problem, but as they came out negative closed. Already open.

1 answer

1


Since I only have to do the requisitioning every minute setTimeout, or setInterval.

setTimeout()

if(req.readyState == 4 && req.status == 200) {

    // Resposta retornada pelo busca.php
    var resposta = req.responseText;

    // Abaixo colocamos a(s) resposta(s) na div resultado
    document.getElementById('resultado').innerHTML = resposta;
    //primeiro argumento é a funcao a ser executada, o segunta o tempo que vai levar ate a funcao ser disparada, em milisegundos.
    setTimeout(buscarRomaneio, 60000);
}

I put the setTimeout() at the end of the requisica, that is how to finish the requisicao will wait 1 minute and make a new requisicao and so on.

The only problem would be if the request returns a status 404 error, then it would break the cycle.

setInterval()

function buscarRomaneio() {
    //seu codigo da requisicao.....
}
setInterval(buscarRomaneio, 60000);

The advantage here is not having to worry whether the requisicao returned error or not, why the function will be called infinitely, regardless of the status of the requisica.

  • Man, no words. Thank you very much. The way I was going to grind the memory, which is already little, of the collector. So I play for the net and let her turn around. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.