I am making chat application but i am confuse where i put setInterval().bellow function working well.

function text_input(id,img)
{
    $("#chat_box").keydown(function (e){
        if(e.keyCode == 13){    
            e.preventDefault();                     
            var textval = $("#chat_box").val().replace(/\n/g,'<br />');      

            $("#chat_box").val('');
                    jQuery.ajax({
                    type: "POST",
                    url:    "chat_input_insert.php?action=save",         //sql querys
                    data:   "textval="+textval+"&id="+id
                    });

                    jQuery.ajax({
                    type: "POST",
                    url:    "chat_input_insert.php?action=display",      //sql querys
                    data:   "textval="+textval+"&id="+id+"&img="+img,
                    success:    function(html)
                        {

                            $("#chat_store").html(html);

                        }
                    });                                 
        }
    });
    return false;
}

Any one can Suggest me.

Thank You

No one have solution or suggestion..Stuff

Member Avatar for Budy_1

something like this ?

   ..,
    complete:function(){

     setInterval("text_input()",3000) //polling every 3 secons
   }

I got my solution.More

setInterval(function() {

                jQuery.ajax({

            type: "POST",
            url:    "chat_input_insert.php?action=display",
            data:   "textval="+textval+"&id="+id+"&img="+img,

            success:    function(html)
                {
                    $("#chat_store").html(html);        
                }
            }); 

            return false;

},1000);            

I hope it will be usefull to others.
Thanks

Member Avatar for Budy_1

Nice solution.

my suggestion is ..when you do a polling request using jquery ajax, do the polling when the request is complete. its also recommended to make function callback outside seInterval.:)

@Budy 1: I really appreciate for your solution.
but in my cash i have simply call "action=display" that have display query of mysql so that.

Thanks for support

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.