6
Well I did one here script to fetch information from real-time posts the database but it works if I add it directly in Mysql works well but the page when I go to insert a text does not work with Mysql and disable the script of long Polling it already adds well to database
Ajax long Polling
<script language="javascript">
var timestamp = null;
function cargar_push() 
{ 
    $.ajax({
    async:  true, 
    type: "POST",
    url: "ajax/funcao.php",
    data: "×tamp="+timestamp,
    dataType:"html",
    success: function(data)
    {   
        var json           = eval("(" + data + ")");
        timestamp          = json.timestamp;
        opiniao            = json.opiniao;
        if(timestamp == null)
        {
        }
        else
        {
            $.ajax({
            async:  true, 
            type: "POST",
            url: "ajax/mostra_posts.php?id_estabelecimento=<?php echo $row->id; ?>",
            data: "",
            dataType:"html",
            success: function(data)
            {   
                $('#mostra_posts').html(data);
            }
            }); 
        }
        setTimeout('cargar_push()',1000);
    }
    });     
}
$(document).ready(function()
{
    cargar_push();
}); 
</script>
Script that adds post
<script type="text/javascript">
$(function() {
    $(".submit_button").click(function() {
        var textcontent = $("#opiniao").val();
        var dataString = 'id_estabelecimento=<?php echo $row->id; ?>&user_id=<?php echo $_SESSION['user_id'] ?>&opiniao='+ textcontent;
        if(textcontent==''){
            alert("Por favor escreva uma opinião..");
            $("#opiniao").focus();
        }else{
            $("#flash").show();
            $("#flash").fadeIn(400).html('<span class="load">Aguarde por favor..</span>');
            $.ajax({
                type: "POST",
                url: "ajax/processa_post.php",
                data: dataString,
                cache: true,
                success: function(html){
                    $("#show").after(html);
                    document.getElementById('opiniao').value='';
                    $("#flash").hide();
                    $("#opiniao").focus();
                }  
            });
        }
        return false;
    });
});
</script>
just one remark, the snippet user_id=<? php echo $_SESSION['user_id'] ? > does not need to be sent this way... this features severe security failure.
– Daniel Omine
Does this script have to do with the comments you are trying to make? Ajax searching the "posts" is giving problem or what adds?
– Rafael Withoeft
Yes I can not find a solution for it to work as long Polling solves as I want but there are few examples on the net to use with mysql
– César Sousa
Look @Césarsousa you have no problem with mysql, review the javascript/php part, study it in ajax and json_encode and rewrite your javascript/php code to do it the right way.
– SneepS NinjA
you’ve solved that issue?
– SneepS NinjA