Problem with div updating content

Asked

Viewed 33 times

0

Well personal I have an ajax script making requests every 1 according to my database to show new content that has been published in the database but I am finding a problem that content always has a form by with a input box to comment and my problem is there as this always making requests every 1 second does not let me write the comment how I can solve this ?

Script

<script>
            //LISTA POSTS ESTABELECIMENTOS
                $(document).ready(function() {
                $.ajaxSetup({ cache: false }); // This part addresses an IE bug.  without it, IE will only load the first number and will never refresh
                setInterval(function() {
                $('#mostra_posts').load('ajax/mostra_posts.php?id_estabelecimento=<?php echo $row->id; ?>');
                }, 1000); // the "3000" here refers to the time to refresh the div.  it is in milliseconds. 
                });
                // ]]>
            </script>

<?php
session_start();
require_once("../gtm/bd/funcoes.php");
ligarBd();  

$id_estabelecimento = $_REQUEST['id_estabelecimento'];

$result_post=mysql_query("select * from posts where estabelecimento_id='".$id_estabelecimento."' order by data desc");
while($row_posts=mysql_fetch_object($result_post)){
$result_user_anex=mysql_query("select * from users_social where id='".$row_posts->user_id."'");
$row_user_anex=mysql_fetch_object($result_user_anex);
?>

<section class="container" style="margin:15px 0px 0px 0px; border-top-left-radius: 2px; border-top-right-radius: 2px;">
<table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td valign="top">
           <div style="float:left; margin:0px 0px 10px 0px; "><img width="50" height="50" src="<?php echo $row_user_anex->user_foto ?>"/></div>
           <h3 style="float:left; margin:15px 0px 0px 10px;"><?php echo utf8_encode($row_user_anex->fb_nome); ?></h3>
        </td>
    </tr>
</table>      
<p><?php echo utf8_encode($row_posts->opiniao); ?></p>
<script>
  FB.init({ appId: '1404139796547995', status: true, cookie: true, xfbml: true, oauth: true });

  function post_fb<?php echo $row_posts->id_post; ?>() {  
    FB.login(function(response) {
      if (response.authResponse) {
        FB.ui({
            method: 'feed', 
             message     : "Vê este comentário sobre <?php echo $row_cat->titulo; ?> no @SabeOnde",
             link        : '<?php echo $row->link_site; ?>',
             picture     : 'http://sabeonde.pt/gtm/anexos/capa/<?php echo $row_capa->id_anexo; ?>.<?php echo $row_capa->tipo ?>',
             name        : '<?php echo $row_cat->titulo; ?> | SabeOnde',
             from: '<?php echo $_SESSION['FBID'] ?>',
             description : '<?php echo $row_posts->opiniao; ?>'                      
        },
        function(response) {
          if (response && response.post_id) {
            alert('Comentário Partilhado com sucesso!');
          } else {
            alert('Falha ao partilhar o comentário');
          }
        });
      } else {
        alert('User cancelled login or did not fully authorize.');
      }
    }, {scope: 'publish_actions, publish_stream'});
    return false;
}
</script>  
<div style="float:left; margin:0px 5px 10px 0px;"><a href="#">Gosto</a></div>
<div style="float:left; margin:0px 5px 10px 0px;"><a href="#" >Comentar</a></div>
<div style="float:left; margin:0px 5px 10px 0px;"><a href="#" onClick="post_fb<?php echo $row_posts->id_post; ?>()">Partilhar</a></div>
</section>
<?php
}
?>
  • Wouldn’t it be better to put in this form out of of that area that constantly updates?

  • Yes but it will get me out of the while presenting me the posts

  • Place your code to facilitate the visualization of your problem.

  • already this ai now I put the comments box out but as it gets out of the while only presents in the last post

  • All this is inside the id div mostra_posts, right?

  • No script is in another file that has the div that shows posts

  • Yes that content is all inside that div

  • Deep down I wanted the part of the comments stay out of the while but it was presented in all posts that already solved my problem but I do not know how I can do seen that out of the while only presents me in the last post

  • You can lend a hand

  • You can help out

Show 5 more comments
No answers

Browser other questions tagged

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