Ajax的自动更新自动更新、Ajax

2023-09-10 21:40:26 作者:君为丶荭颜恋

我有一个div,我想告诉6图像。这些图像的地址是由服务器来了。我用这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);
                                },
                                error : function(XMLHttpRequest, textStatus, errorThrown) {
                                    alert("Error: "+errorThrown);
                                }
                            });
                            document.write(count);
                        };

这code更新我的div标签。不过,我想送每次5秒,这将如果数据是不同的再次更新div标签后,到服务器的请求。因为这是在数据库中图片地址自动改变。所以我想,一旦这些地址在我的数据库更改更新div标签。这可能吗?

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?

在此先感谢

推荐答案

我建议使用定时器功能,因为它会完成这项工作。

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

如何设置另一个功能根据您的更新功能调用。有在jQuery的过程(功能)功能YourFunctionName叫你做更新div标签。

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