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