Ajax的自动更新 [英] Ajax Auto update

查看:122
本文介绍了Ajax的自动更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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);
                            };

这篇关于Ajax的自动更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆