0
    <script type="text/javascript">
        function bindCity() {
    // Some javascript code
                //declare options array and populate
                var modelnames = new Array();
                $.get("file.php?mt=" + qs, function(data) {
                        eval(data);
                        if(modelnames.length > 0) {
                            addOptions(modelnames);
                        }
                    }
                );
            }
        function addOptions(cl) {
            //enable child select and clear current child options
            $("#mn").removeAttr("disabled");
            $("#mn").html('');
            //repopulate child list with array from helper page
            var city = document.getElementById('mn');
            for(var i = 0; i < cl.length; i++) {
                city.options[i] = new Option(cl[i].text, cl[i].value);
            }
        }
    </script>

这是 PHP 脚本(将值获取到 $mt 之后):-

$SQLqueryTry = "SELECT mn FROM pd WHERE pd_mt = '$mt'";
    $SQLqueryETry = mysql_query($SQLqueryTry, $dacreint) or die(mysql_error());
    while ($Try = mysql_fetch_array($SQLqueryETry))
    {
        $output = "modelnames.push(new Option('$Try[mn]', '$Try[mn]'));\n";
    }

我在 PHP 文件中的输出代码:-

header('Content-type: text/plain');
echo $output;

现在我只能获取一个值$output = "modelnames.push(new Option('$Try[mn]', '$Try[mn]'));\n";

但是,当我添加.$output =$output .= "modelnames.push(new Option('$Try[mn]', '$Try[mn]'));\n";

我无法获得任何价值。问题是什么?

4

1 回答 1

0

您是否能够在错误日志中看到任何错误?

我的第一个猜测是您忘记$output在使用变量之前对其进行初始化.=

也许尝试:

$output = "";
while ($Try = mysql_fetch_array($SQLqueryETry))
{
    $output .= "modelnames.push(new Option('$Try[mn]', '$Try[mn]'));\n";
}
于 2012-04-05T12:10:49.010 回答