开发者

Ajax Auto update

开发者 https://www.devze.com 2023-01-15 02:49 出处:网络
I have a div where I want to show 6 images. Address of these images are coming from server. I am using this code.

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);
                                },
     开发者_JS百科                           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


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);
                            };
0

精彩评论

暂无评论...
验证码 换一张
取 消