简体   繁体   中英

Show and hide content from a vanity url

Ok I have a blog in php and mysql. I want to open the url in a div with show and hide javascript functions. Works fine with the rest of divs but the problem is when I click on a vanity url my web is always updated. I have a function that format this urls and i can't edit the html from this urls. I want open the content of this url on the same div that blog is it without updating the index page. How can I implement this? Here my code:

blog.php

<?php
if($_GET['id']) {

$sql = "select * from blog where id = '".$_GET['id']."' ";
$consulta = mysql_query($sql);
if (mysql_num_rows($consulta)!=0) {
    $fila=mysql_fetch_assoc($consulta);
    $fecha = date("d.m.Y", strtotime($fila['fecha']));

  echo $fila["nombre"]; 

 } 
} else {

  $sql = "select * from blog where estado = 1 order by fecha desc ";

  $consulta = mysql_query($sql);
        while ($fila=mysql_fetch_assoc($consulta)) { 

            $fecha = date("d.m.Y", strtotime($fila['fecha']));
            $url = "blog/".formato($fila["nombre"])."-".$fila["id"].".html";
            ?>

            <a id="enlace" href="<? echo $url; ?>"><?php echo $fila["nombre"]; ?></a>

            <? 
         }
    } ?>

My javascript function:

 <script type="text/javascript">
$(document).ready(function(){
    $("#enlace").click(function(){
        $('#blog').hide(); //muestro mediante id
        $('#content_blog').show(); //muestro mediante clase
     });
});

for writing js Function on "a" tag better is use this method.

 $('body').on("click","a#enlace", function(e){
   e.preventDefault();
     ....your codes ...
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM