Ir para conteúdo

Arquivado

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

Paulo Vinícius Matos

Retorno em uma <div> com ajax

Recommended Posts

Bom dia! Galera, to tentando da um retorno de uma consulta via ajax para uma div. Porém, sem sucesso. Desde de já, obrigado a todos que leram e tentaram ajudar.

[]'s

 

Segue os códigos:

 

Função JS que que envia via ajax:

function consulta_clipping(){
    $.ajax({
method: 'post',
url: 'consulta/busca.php',
data: {dt_inicial: dt_inicial, dt_final: dt_final},
success: function(data){
$('#formulario_modal').html(data)
}
});
}

Html montado pelo PHP:

<?php
$response ='<fieldset class="formulario"><legend class="alt">Consulta Clipping </legend>';
$response .='<form name="formx" id="formx">';
$response .='<label for="dt_inicial"> De: </label><input name="dt_inicial" type="text" id="dt_inicial">';
$response .='até';
$response .='<input name="dt_final" type="text" id="dt_final">';
$response .='<input name="buscar" type="SUBMIT"  value="buscar" onclick="consulta_clipping();">';
$response .='</form>';
$response .='<div id="formulario_modal"></div></fieldset>';
echo $response;
?>	

 

Arquivo que envia para o banco:

 

<?php
echo '<fieldset class="formulario">';
require('../conn/conn.php');
require('../funcoes/funcoes.php');

echo "<table border='0'><thead><tr>
		<th>Cod. Clipping</th>
		<th>Título</th>
		<th>Data Publicacao</th>
		<th>Página</th>
		<th>Caderno</th>
		<th>Editoria</th></thead>";

echo "<tbody>";
$dt_inicial = $_POST['dt_inicial'];
$dt_final = $_POST['dt_final'];

//convertendo data para enviar ao bd em formato AAAA/MM/DD
$data_sql = data_to_sql($dt_inicial);
$dt_sql = data_to_sql($dt_final);

$sql="SELECT m.id, m.titulo, m.dt_publicacao, l.pagina, l.caderno, l.editoria FROM materia m INNER JOIN localizacao l ON m.id_localizacao = l.id
WHERE m.dt_publicacao BETWEEN '$data_sql' AND '$dt_sql'";
	$listagem = mysql_query($sql);
		while($row = mysql_fetch_array($listagem)) {
		//convertendo a saída para formato BR
			$dt_saida = data_from_sql($row['dt_publicacao']);
		
			echo "<tr>";
			echo "<td>" . $row['id'] . "</td>";
			echo "<td>" . $row['titulo'] . "</td>";
			echo "<td>" . $dt_saida . "</td>";
			echo "<td>" . $row['pagina'] . "</td>";
			echo "<td>" . $row['caderno'] . "</td>";
			echo "<td>" . $row['editoria'] . "</td>";
			echo "</tr>";
		}
echo "</tbody></table>";
echo '</fieldset>';

?>

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Corrigir alguns erro na minha função js, mas nada funcinou.

 

function consulta_clipping() {
 var dt_inicial = $("#dt_inicial").val();
 var dt_final = $("#dt_final").val();
    $.ajax({
        method: 'post',
        url: 'consulta/busca.php',
        data: {
            dt_inicial: dt_inicial,
            dt_final: dt_final
        },
        success: function (data) {
            $('#formulario').html(data);
			
        }
    });
}

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

vc precisa ter algum elemento com o id="formulario" na página q faz o ajax.

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.