Php 需要显示用户';在magento中的实时选择

Php 需要显示用户';在magento中的实时选择,php,javascript,ajax,magento,Php,Javascript,Ajax,Magento,我正在开发一个magento webstore,其中有一个页面,客户可以在其中选择他/她想要获取订单的路线。选择是双重的,目前有两套不同的按钮,因此没有复选框或单选按钮。用户首先选择日期,然后选择地点 现在我正在调用一个javascript函数,该函数在按下按钮时加载一个cookie,然后重新加载页面,并将用户返回到一个锚链接,这样用户在进行第一次选择时就不会混淆自己在哪里。当页面重新加载时,边栏包含读取cookie内容的php。这感觉不是很直观,我相信有更好的方法来做到这一点。用户所做的选择应

我正在开发一个magento webstore,其中有一个页面,客户可以在其中选择他/她想要获取订单的路线。选择是双重的,目前有两套不同的按钮,因此没有复选框或单选按钮。用户首先选择日期,然后选择地点

现在我正在调用一个javascript函数,该函数在按下按钮时加载一个cookie,然后重新加载页面,并将用户返回到一个锚链接,这样用户在进行第一次选择时就不会混淆自己在哪里。当页面重新加载时,边栏包含读取cookie内容的php。这感觉不是很直观,我相信有更好的方法来做到这一点。用户所做的选择应该显示在边栏购物车上,边栏购物车是一个.phtml文件。只要一句简单的“你已经选择了路径x”就足够了,现在我有一个回音,但页面必须先重新加载

因此,简言之,当用户做出选择时,侧边栏应该更新有关选择的信息,而不必重新加载页面本身并借助锚链接返回位置。通知最好位于左侧边栏中。我不想使用弹出窗口或临时通知,但它们可能是一个附加功能


我敢肯定这是一个非常简单的问题,但由于某些原因,我似乎找不到正确的关键字,然后是magento本身

好的,这是迄今为止我提出的最好的一个。我仍然认为它只是部分解决了,我想我可以从MaGuto社区得到更多的帮助,但现在它工作得很好。 将此脚本包括到custom.phtml头中:

<script type="text/javascript">
function AJAX(){
   try{
      xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
      return xmlHttp;
   }
   catch (e){
      try{
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
         return xmlHttp;
      }
      catch (e){
         try{
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            return xmlHttp;
         }
         catch (e){
            alert("Your browser does not support AJAX.");
            return false;
         }
      }
   }
}


// Timestamp for preventing IE caching the GET request (common function)

function fetch_unix_timestamp()
{
    return parseInt(new Date().getTime().toString().substring(0, 10))
}

// Reload div with php

function refreshdiv_timediv(){

   var seconds = '3';
   var divid = "ajax";
   var url = "routes/customer_needs_to_see_this.php";

   var xmlHttp_one = AJAX();

   // No cache

   var timestamp = fetch_unix_timestamp();
   var nocacheurl = url+"?t="+timestamp;


   // The code...

   xmlHttp_one.onreadystatechange=function(){
      if(xmlHttp_one.readyState==4){
         document.getElementById(divid).innerHTML=xmlHttp_one.responseText;
         setTimeout('refreshdiv_timediv()',seconds*1000);
      }
   }
   xmlHttp_one.open("GET",nocacheurl,true);
   xmlHttp_one.send(null);
}

// Start the refreshing process

window.onload = function startrefresh(){
   setTimeout('refreshdiv_timediv()',seconds*1000);
}
</script>

函数AJAX(){
试一试{
xmlHttp=newXMLHttpRequest();//Firefox、Opera 8.0+、Safari
返回xmlHttp;
}
捕获(e){
试一试{
xmlHttp=newActiveXObject(“Msxml2.xmlHttp”);//Internet Explorer
返回xmlHttp;
}
捕获(e){
试一试{
xmlHttp=新的ActiveXObject(“Microsoft.xmlHttp”);
返回xmlHttp;
}
捕获(e){
警报(“您的浏览器不支持AJAX。”);
返回false;
}
}
}
}
//防止IE缓存GET请求的时间戳(通用函数)
函数fetch_unix_timestamp()
{
返回parseInt(新日期().getTime().toString().substring(0,10))
}
//用php重新加载div
函数refreshdiv_timediv(){
变量秒数='3';
var divid=“ajax”;
var url=“routes/customer\u需要\u查看\u this.php”;
var xmlHttp_one=AJAX();
//无缓存
var timestamp=fetch_unix_timestamp();
var nocacheurl=url+“?t=“+时间戳;
//代码。。。
xmlHttp_one.onreadystatechange=函数(){
if(xmlHttp_one.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp_one.responseText;
setTimeout('refreshdiv_timediv()',秒*1000);
}
}
xmlHttp_one.open(“GET”,nocacheurl,true);
xmlHttp_one.send(空);
}
//启动刷新过程
window.onload=函数startrefresh(){
setTimeout('refreshdiv_timediv()',秒*1000);
}
然后我将customer_needs_to_see_this.php to文件夹路由放置在www根目录中。上面的脚本将自动刷新div“ajax”,在ajax div中有一个php include
routes/user\u needs\u\u see\u this.php
。包含的div位于
cart\u侧栏。phtml

我不得不将该文件放在magento的模板文件之外,因为我无法执行诸如
。/template/checkout/customer\u-needs\u-to\u-see\u-this.php
。当它们与视图(phtml文件)文件位于同一文件夹中时包括工作,但在其他情况下似乎不工作。另外,我无法从magento的模板文件中获取
用户\u需要\u查看\u this.php
的脚本

现在,当客户在
custom.phtml
页面上时,它每3秒钟更新一次。我认为这没关系,因为它只是阅读和做饼干,所以它不重。将来我可能会把它改成onclick

我知道密码了


还有很多其他类似的例子,但上面的例子似乎涵盖了大部分基础。

好的,这是我迄今为止提出的最好的例子。我仍然认为它只是部分解决了,我想我可以从MaGuto社区得到更多的帮助,但现在它工作得很好。 将此脚本包括到custom.phtml头中:

<script type="text/javascript">
function AJAX(){
   try{
      xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
      return xmlHttp;
   }
   catch (e){
      try{
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
         return xmlHttp;
      }
      catch (e){
         try{
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            return xmlHttp;
         }
         catch (e){
            alert("Your browser does not support AJAX.");
            return false;
         }
      }
   }
}


// Timestamp for preventing IE caching the GET request (common function)

function fetch_unix_timestamp()
{
    return parseInt(new Date().getTime().toString().substring(0, 10))
}

// Reload div with php

function refreshdiv_timediv(){

   var seconds = '3';
   var divid = "ajax";
   var url = "routes/customer_needs_to_see_this.php";

   var xmlHttp_one = AJAX();

   // No cache

   var timestamp = fetch_unix_timestamp();
   var nocacheurl = url+"?t="+timestamp;


   // The code...

   xmlHttp_one.onreadystatechange=function(){
      if(xmlHttp_one.readyState==4){
         document.getElementById(divid).innerHTML=xmlHttp_one.responseText;
         setTimeout('refreshdiv_timediv()',seconds*1000);
      }
   }
   xmlHttp_one.open("GET",nocacheurl,true);
   xmlHttp_one.send(null);
}

// Start the refreshing process

window.onload = function startrefresh(){
   setTimeout('refreshdiv_timediv()',seconds*1000);
}
</script>

函数AJAX(){
试一试{
xmlHttp=newXMLHttpRequest();//Firefox、Opera 8.0+、Safari
返回xmlHttp;
}
捕获(e){
试一试{
xmlHttp=newActiveXObject(“Msxml2.xmlHttp”);//Internet Explorer
返回xmlHttp;
}
捕获(e){
试一试{
xmlHttp=新的ActiveXObject(“Microsoft.xmlHttp”);
返回xmlHttp;
}
捕获(e){
警报(“您的浏览器不支持AJAX。”);
返回false;
}
}
}
}
//防止IE缓存GET请求的时间戳(通用函数)
函数fetch_unix_timestamp()
{
返回parseInt(新日期().getTime().toString().substring(0,10))
}
//用php重新加载div
函数refreshdiv_timediv(){
变量秒数='3';
var divid=“ajax”;
var url=“routes/customer\u需要\u查看\u this.php”;
var xmlHttp_one=AJAX();
//无缓存
var timestamp=fetch_unix_timestamp();
var nocacheurl=url+“?t=“+时间戳;
//代码。。。
xmlHttp_one.onreadystatechange=函数(){
if(xmlHttp_one.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp_one.responseText;
setTimeout('refreshdiv_timediv()',秒*1000);
}
}
xmlHttp_one.open(“GET”,nocacheurl,true);
xmlHttp_one.send(空);
}
//启动刷新过程
window.onload=函数startrefresh(){
setTimeout('refreshdiv_timediv()',秒*1000);
}
然后我将customer_needs_to_see_this.php to文件夹routes放入www root director中