【问题标题】:Magento displays same page inside the visible page when trying to send/receive data from another php尝试从另一个 php 发送/接收数据时,Magento 在可见页面内显示相同的页面
【发布时间】:2013-05-21 13:46:42
【问题描述】:

我正在尝试在几周前创建的自定义后端模块上创建新功能。新功能包括进行查询,以便在“选择选项”中列出来自特定客户的一些数据。然后,当我选择其中一个选项时,我制作了一个脚本,它的作用是捕获该选项,使用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>

最后,必须与我通过方法 GET 发送的信息进行交互的 PHP 是 (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有些不一致。或者如果有人知道更好的方法,请告诉我。

【问题讨论】:

    标签: php magento


    【解决方案1】:

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

    您的问题的解决方案是您可以为receiveselection.php 创建一个控制器操作 假设 receiveelectionAction 将您的代码更改为此

    xmlhttp.open("GET","your_module/your_controller/receiveselection.php?q="+str,true);
    

    【讨论】:

    • 抱歉耽搁了回复您。非常感谢您的回答,我很绝望。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-12
    • 2020-08-16
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多