php - 根据我的要求更改客户端浏览器中的图像

标签 php mysql ajax

我有一个 friend 通过电话给他的客户打电话。他想在他的网站上展示他的产品。 但为了确保他们看到他想要销售的产品,他希望他们转到一个他可以按需更改图片的页面。就像在客户端浏览器中运行 powerpoint 演示文稿一样。 例如,如果客户需要其他功能,他可以显示另一张图片。

  1. 在通话过程中,客户转到我 friend 网站上的特定页面。
  2. 所显示的图像或 html 数据可按我 friend 的要求更改。

这可以通过 AJAX 轻松实现吗?

最佳答案

当然可以!

客户端:

<script type="text/javascript">
//The first image to load
CurrentImage="http://images.google.com/intl/en_ALL/images/logos/images_logo_lg.gif";

//The Image, eg: <img id=imgBox src=foo.jpg>
ImgBox = document.getElementById('imgBox');

function CheckForImg()
{
    var ajaxRequest;  // The variable that makes Ajax possible! 
        try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
        } catch (e){
        try
            {
        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try{
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e){
            // Something went wrong
            alert("Ajax is kinda disabled :(\n you won't be able to do some stuff around :(");
            return false;
        }
    }
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){    
    if(ajaxRequest.readyState == 4){
        var str = ajaxRequest.responseText;
        if(str != CurrentImage) // we have a new image
        {
            ImgBox.src = str;
            currentImage = str;
        }
    }
ajaxRequest.open("GET", "getCurrentImagUrl.php", true);
ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
ajaxRequest.send(null);
}
</script>

现在我们需要一种方法来让客户保持最新状态,所以我们要么将其设置为一个频率,要么显示一个按钮以按下哪个更好、更有效:

方法一(按钮):

<Button onclick="CheckForImg();">Check For Image!</button>

方法二(定期检查):

简单调用

SetInterval("CheckForImg", 5000);

我会把服务器端留给你:)

如有任何进一步的帮助,我们将竭诚提供。

关于php - 根据我的要求更改客户端浏览器中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15583935/

相关文章:

php - 如何用PHP制作不规则表格?

javascript - 在 ie8 中添加选项时动态选择卡住

javascript - 从另一个网站(雅虎)获取值(value)?

PHP-用多列的最小值更新一列

php - Paypal API - CURRENCY_NOT_ALLOWED

php - 避免在插入手动递增的收据编号时发生冲突

使用 XAMPP 和 MySQL 的 PHP 登录脚本

javascript - 返回所有用户、每个用户的帖子以及每个带有评论的帖子 laravel

php - 如何检测 php curl 中的 URL Not Found 错误?

While 循环中的 PHP 语法错误