2013-03-23 80 views
1

我有一位朋友通过电话呼叫他的客户。他想在他的网站上展示他的产品。 但是,为了确保他们看到他想销售的产品,他希望他们进入一个页面,他可以根据需求更改图像。就像在客户端浏览器中运行PowerPoint演示文稿一样。 如果客户端需要其他功能,他可以显示其他图像。根据我的需求在客户端浏览器中更改图片

  1. 在通话期间,客户端转到我朋友网站上的特定页面。
  2. 显示的图像或html数据根据需要由我的朋友更改。

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

回答

0

当然!

客户端:

<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> 

现在,我们需要一种方法来保持客户端发布,所以我们要么把那一个频率,或显示一个按钮,按下它是更好的方式,更高效:

方法1(按钮):

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

方法2(定期检查):

要获取

SetInterval("CheckForImg", 5000); 

我将离开服务器端为您:)

任何进一步的帮助是好心提供。