使用ajax的javascript函数出现引用错误

使用ajax的javascript函数出现引用错误,javascript,ajax,Javascript,Ajax,我使用ajax在mysql数据库上使用关键字搜索,当搜索结果出来时,我想用onclick函数将选项显示为href,搜索效果很好,但是当我单击任何选项时,我在firebug上得到一个引用错误,代码如下: index.php <html> <body> <style> #displayDiv { background-color: #ffeeaa; width: 200;

我使用ajax在mysql数据库上使用关键字搜索,当搜索结果出来时,我想用onclick函数将选项显示为href,搜索效果很好,但是当我单击任何选项时,我在firebug上得到一个引用错误,代码如下: index.php

 <html>

<body>
    <style>
        #displayDiv {
            background-color: #ffeeaa;
            width: 200;
        }
    </style>
    <script type="text/javascript">
        function aca(esto) {
            var esta = esto;
            alert(esta);
        }
    </script>
    <script type="text/javascript">
        function ajaxFunction(str) {
            var httpxml;
            try {
                // Firefox, Opera 8.0+, Safari
                httpxml = new XMLHttpRequest();
            } catch (e) {
                // Internet Explorer
                try {
                    httpxml = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                    try {
                        httpxml = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) {
                        alert("Your browser does not support AJAX!");
                        return false;
                    }
                }
            }

            function stateChanged() {
                if (httpxml.readyState == 4) {
                    document.getElementById("displayDiv").innerHTML = httpxml.responseText;

                }
            }
            var url = "search.php";
            url = url + "?txt=" + str;
            url = url + "&sid=" + Math.random();
            httpxml.onreadystatechange = stateChanged;
            httpxml.open("GET", url, true);
            httpxml.send(null);
        }
    </script>
    </head>
    
    <body>
        <form name="myForm">
            <input type="text" onkeyup="ajaxFunction(this.value);" name="username"
            />
            <div id="displayDiv"></div>
        </form>
    </body>

#displayDiv{
背景色:#ffeeaa;
宽度:200;
}
功能aca(esto){
var-esta=esto;
警报(esta);
}
函数ajaxFunction(str){
var-httpxml;
试一试{
//Firefox、Opera 8.0+、Safari
httpxml=新的XMLHttpRequest();
}捕获(e){
//Internet Explorer
试一试{
httpxml=新的ActiveXObject(“Msxml2.XMLHTTP”);
}捕获(e){
试一试{
httpxml=新的ActiveXObject(“Microsoft.XMLHTTP”);
}捕获(e){
警告(“您的浏览器不支持AJAX!”);
返回false;
}
}
}
函数stateChanged(){
if(httpxml.readyState==4){
document.getElementById(“displayDiv”).innerHTML=httpxml.responseText;
}
}
var url=“search.php”;
url=url+“?txt=“+str;
url=url+“&sid=“+Math.random();
httpxml.onreadystatechange=stateChanged;
open(“GET”,url,true);
httpxml.send(null);
}
这是search.php

<?php
include ("dbinfo.php");
$in = $_GET['txt'];
$msg = "";
if (strlen($in) > 0 and strlen($in) < 20) {
    $t = mysql_query("select RubroId, RubroDisp from rubros where KeyWords like '$in%'");
    while ($nt = mysql_fetch_array($t)) {
        $valor = $nt[RubroDisp];
        $valorCodificado = str_replace(" ", "_", $valor);
        echo "<a href='#' onclick='aca($valorCodificado);'>$valor</a><br />";
        
                                        }
                                          }
?>

aca($valorCodificado)
将生成JavaScript,该JavaScript使用参数的变量(可能不存在)调用函数。看起来你需要一根绳子。字符串需要引号。

请缩进代码!我在Chrome中没有任何错误,请友好一点,在这里写下完整的错误消息(如果可能的话,写上行号)。还请告诉我们您使用的浏览器。这是我在firebug中遇到的错误:ReferenceError:Cerramientos_de_Aluminio未定义[Parar en este error]aca(Cerramientos_de_Aluminio);代码缩进了,对不起