2

我正在尝试在几周前创建的自定义后端模块上创建新功能。新功能包括进行查询,以便在“选择选项”中列出来自特定客户的一些数据。然后,当我选择其中一个选项时,我制作了一个脚本,它的作用是捕获该选项,将其与GET方法一起发送到另一个 .php,然后,php 使用所选数据进行某些操作,然后使用任何。

代码如下(data.phtml):

<script language="JavaScript" type="text/javascript">
    function showPresu(str){
    if (str=="")
    {
    document.getElementById("txtHint").innerHTML="";
    alert('nothing here');
    return;
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
        alert('makes request');
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        alert('new object');
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","receiveselection.php?q="+str,true);
    xmlhttp.send();
    }
    </script>

如您所见,我编写了一些警报,以确保代码进入脚本内部。

选择/选项如下(data.phtml):

echo '<select name="presus" onchange="showPresu(this.value)">';
    for($n=1;$n<=$h; $n++){
        echo "<option value='$status_id[$n]'>$status_id[$n]";
    }
    echo "</select>";

$status_id[$x]:是一个数组,里面包含了我一开始介绍的一些数据。

必须显示最终数据的 div 是 ( data.phtml):

<div id="txtHint">
<b>result info will be listed here.</b>
</div>

最后,必须与我通过方法发送的信息进行交互的 PHPGET是 ( receiveselection.php,与 . 位于同一文件夹中data.phtml。请注意,此 PHP 将更改为另一个代码,我的意思是,我将更改以下代码以进行另一个查询,但现在可以进行测试了):

<?php
$q=$_GET["q"];
echo $q;
?>

唯一的问题是,当我尝试在为此创建的 div 中显示 'receiveselecton.php' 时,而不是查看 'receiveselection.php' 的结果,它会显示与我在前一刻相同的 magento 页面(data.phtml) ,我的意思是,它在同一页面出现两次,一次是“正常”,另一次在div.

有谁知道如何调用receiveselection.php而不是创建另一个data.phtml

编辑:如果我把这段代码放在 magento 之外,它可以工作,但在里面却不行。所以问题可能是我不知道的与 magento 不一致的地方。或者如果有人知道更好的方法,请告诉我。

4

1 回答 1

0

我在我的系统中尝试了你的代码,它工作正常。我发现的问题是你发送的请求无法到达文件 receiveelection.php

您的问题的解决方案是您可以为receiveselection.php 创建一个控制器操作让我们说receiveselectionAction 将您的代码更改为此

xmlhttp.open("GET","your_module/your_controller/receiveselection.php?q="+str,true);
于 2013-05-23T10:31:11.450 回答