Searching for PHP data by Ajax

1

I have a Ajax script here that its function is as follows. I have a news system, which when clicking on the title will open a modal and display the data of the news (title, text, author) .. however I do not know what to put in PHP ..

This is the js code

var News = {
Init: function(id) {
    $.ajax({
        url: 'noticia.php',
        type: 'POST',
        dataType: 'json',
        data: {'id': id},
        beforeSend: function(){
            $('body').animate({'opacity':'0.5'});
        },success: function(data) {
            $('body').animate({'opacity':'1'});
            var Html = '';
                Html+='<div id="modal" class="animated bounceInDown">';
                Html+='     <div class="ler_content animated bounceInDown"> <div id="close_new" onclick="Alerta.Close()"></div>';
                Html+='         <div class="titulo">';
                Html+='            <div class="img" style="background: url('+data['imagem']+');">';
                Html+='            </div>';
                Html+='           <div class="autor">'+data['autor']+'</div>';
                Html+='           <span>'+data['titulo']+'</span>';
                Html+='        </div>';
                Html+='        <div class="texto">'+data['texto']+'</div>';
                Html+='     </div>';
                Html+=' </div>';

            $('body').prepend(Html);

        }

    })



}}

What I'm trying to put in the noticia.php is this, but I know it's wrong ..

$id = mysql_real_escape_string( $_GET['id'] );
$data = array();
$sql = "SELECT id, titulo, imagem, autor, texto
    FROM noticias
    WHERE id=$id
    ORDER BY id";
$res = mysql_query( $sql );
while ( $row = mysql_fetch_assoc( $res ) ) {
$data[] = array(
    'id'    => $row['id'],
    'titulo'            => $row['titulo'],
    'imagem'            => $row['imagem'],
    'autor'         => $row['autor'],
    'texto'         => $row['texto'],
);}
echo( json_encode( $data ) );

Help me !!

    
asked by anonymous 14.05.2016 / 18:29

0 answers