0

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

2
Contributors
5
Replies
31
Views
3 Years
Discussion Span
Last Post by ravi142
0

something like this ?

   ..,
    complete:function(){

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

Edited by Budy_1: typo

0

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

0

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.:)

0

@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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.