tags:

views:

107

answers:

2
+1  Q: 

Ajax Auto update

I have a div where I want to show 6 images. Address of these images are coming from server. I am using this code.

updateImageDiv = function() {
                            $.ajax({
                                type : 'POST',
                                url : 'slider.php',
                                dataType : 'json',
                                data: {
                                    p_CustomerName : "Davide"
                                },
                                async:true,
                                success : function(data){
                                    $("#slider").html(data);
                                },
                                error : function(XMLHttpRequest, textStatus, errorThrown) {
                                    alert("Error: "+errorThrown);
                                }
                            });
                            document.write(count);
                        };

This code update my div tag. But I want to send requests to server after each 5 seconds which will update the div tag again if data is different. Because Image addresses which are in database are changing automatically. So I want to update the div tag as soon as these addresses change in my database. Is it possible?

Thanks in advance

+1  A: 

I suggest using the timer function as it will get the job done.

How about setting up another function to call upon your updating function. have the function YourFunctionName call upon the jquery process(function) you made to update the div tag.

setInterval ("YourFunctionName", 5000 );


    updateImageDiv = function() {
                                $.ajax({
                                    type : 'POST',
                                    url : 'slider.php',
                                    dataType : 'json',
                                    data: {
                                        p_CustomerName : "Davide"
                                    },
                                    async:true,
                                    success : function(data){
                                        $("#slider").html(data);
                                    },
                                    error : function(XMLHttpRequest, textStatus, errorThrown) {
                                        alert("Error: "+errorThrown);
                                    }
                                });
                                document.write(count);
                            };
cmptrwhz
It doesn't work. ;(
EarnWhileLearn
A: 

It is also possible by using websockets, but their support is limited for now, and you have to use adobe flash based workarounds.

lashtal