php - Javascript for like system -


i have newsfeed , have created system it. have following code newsfeed , system part of page:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en""http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> <link href="/local_home.css" rel="stylesheet" type="text/css" /> <?php  include '/head.php'; include '/connect.php'; include '/general.php';  ?>  </head>  <body> <!-- begin: sticky header --> <div id="top_container"> <div id="header_container">     <div id="header">         <a href="website.com" class="grand_button">website</a>     </div> </div> <!-- end: sticky header -->  <div class="feed_selector"> <ul>     <li><a href="#">community</a></li>     <li><a href="#">local</a></li>     <li><a href="#">global</a></li> </ul>  </div>  </div> <!-- begin: page content --> <div id="container"> <div id="content">      <div class="select_box">     feed options      </div> <!--- feed container ---!>    <div class="feed_container">    <h1>local feed</h1>         <div class="hr"></div>         <?php         $getnews = mysql_query("select * news order post_id desc") or die(mysql_error());         while ($row = mysql_fetch_assoc($getnews)) {             $id = $row['post_id'];             $title = $row['title'];             $body = $row['body'];             $date = $row['date'];             $likes = $row['post_likes'];             ?>             <div class="deals">             <div class="title"><?php echo $title ?><a class="like_button" href='#' onclick="like_add(' ,$id, ')">like</a>             <br><?php echo '<span class="like_button" id="post_', $id ,'_likes">', $likes, '</span>'?></div>             <br>             <?php echo nl2br($body); ?>             <br><div class="date_time"><?php echo(time_ago($date)) ?></div>             <div class="hr"></div>             </div>          <?php         }         ?>    </div>  </div> <!-- end: page content -->  <!-- begin: sticky footer --> <div id="footer_container"> <div id="footer">     footer content </div> </div> </div> <!-- end: sticky footer --> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/like.js"></script> </body> </html> 

like.js used change amount of likes displayed. contains 2 functions like_add , like_get.

function like_add(post_id){ $.post('ajax/like_add.php', {post_id:post_id}, function(data){     if(data === 'success'){         like_get(post_id);     }else{         alert(data);         } }); }  function like_get(post_id){ $.post('ajax/like_get.php', {post_id:post_id}, function(data){     $('#article_'+post_id+'_likes').text(data); }); } 

i have 2 ajax files like_add , like_get echoing correct things make both statements work should test it.

this means going wrong in javacript because when click button number stays @ zero. getting no errors or warnings odd reason can not javascript work correct. new javascript logic seems correct me. not connecting javascript correctly in first code?

thanks lot!

maybe overlooked first problem you're targeting wrong element:

you give id of post_', $id ,'_likes , try update article_'+post_id+'_likes

$('#article_'+post_id+'_likes').text(data); 

aside that, concatenation in php done . not , i'm surprised working @ all. line looks suspicious me:

<?php echo '<span class="like_button" id="post_', $id ,'_likes">', $likes, '</span>'?> 

why not this:

<span class="like_button" id="post_<?php echo $id; ?>_likes"><?php echo $likes; ?></span> 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -