我几个星期前创建了'm trying to make a new functionality on a custom back-end module that I' ve . 新功能包括进行查询以便列出来自特定客户的一些数据 . 然后,当我选择其中一个选项时,我已经制作了一个脚本,它可以捕获该选项,使用 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>
您可以注意到我已经编写了一些警报,以确保代码进入脚本内部 .
select /选项如下( 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>
最后,必须与我通过方法 GET
发送的信息进行交互的PHP是( receiveselection.php
,与 data.phtml
在同一文件夹中 . 请注意,此PHP将更改为另一个代码,我的意思是,我将以下代码更改为再做一个查询,但现在进行测试就可以了:)
<?php
$q=$_GET["q"];
echo $q;
?>
唯一的问题是,当我试图在创建的div中显示'receiveselecton.php'时,而不是观察'receiveselection.php'的结果,它看起来像我之前的那个magento页面( data.phtml
),我的意思是,它似乎是相同的页面两次,一个作为'normal',另一个作为 div
.
有谁知道如何调用 receiveselection.php
而不是创建另一个 data.phtml
?
编辑:如果我把这个代码放在magento之外它可以工作,但在里面却没有 . 所以问题可能是与我不知道的magento有些不连贯 . 或者,如果有人知道更好的方法,请告诉我 .
1 回答
我尝试你的代码在我的sustem它工作正常..我想出的问题是你发送的请求无法到达文件receiveselection.php
你的问题的解决方案是你可以为receiveselection创建一个控制器动作 . 让我们说receiveselectionAction将你的代码更改为