【问题标题】:Undefined index PHP code [closed]未定义的索引PHP代码[关闭]
【发布时间】:2013-04-11 00:18:10
【问题描述】:

我有这个使用 ajax 的 php

cotizaciones.php

        <script>
        function showUser(str)
        {
            if (str == "")
            {
                document.getElementById("txtHint").innerHTML = "";
                return;
            }
            if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }
            else
            {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function()
            {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
                    document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET", "getuser.php?q=" + str, true);
            xmlhttp.send();
        }
    </script>

我还有另一个脚本,除了它叫做calcularCuotas(cuotas),最后几行是:

xmlhttp.open("GET", "getuser.php?c=" + str, true);
                xmlhttp.send();

body 标签包含:

<select name="users" onchange="showUser(this.value)">
<select name="cuotas" onchange="calcularCuota(this.value)">

文件getuser.php

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

当我尝试使用它时,php会抛出这个错误:

注意:未定义的索引:C:\wamp\www\Cotizacion\getuser.php 中第 3 行的 c

感谢您的帮助:)

【问题讨论】:

  • 错误信息不明白怎么办?

标签: php ajax html


【解决方案1】:

在您的第一个代码块中,即 cotizaciones.php

xmlhttp.open("GET", "getuser.php?q=" + str, true);

它不包含 c 作为查询字符串,因此您会收到错误 undefined index c

【讨论】:

  • 查询字符串中包含 c 的方法相同,但仍然无法正常工作
【解决方案2】:

使用 Jquery 的 Ajax 库,这只是一个建议。

Jquery:Ajax

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    • 1970-01-01
    • 2016-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多