-1

我试图在参数化函数中发送一个数组值,但我不知道为什么我不能这样做。示例代码是:

<ul>
    <?php

    while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
        $photoname = $row['photoname'];
        $string    = array();
        $recreated = 'cmVjcmVhdGVk/';
        $thumb     = 'dGh1bWI=/';
        $original  = 'b3JpZ2luYWw=/';
        $filePath  = "albums/$album/$album$thumb";
        $dir       = opendir($filePath);
        while ($file = readdir($dir)) {
            $info = pathinfo($file);
            if (($info["extension"] == "jpg") || ($info["extension"] == "gif") || ($info["extension"] == "png")) {
                $string[] = $file;
            }
        }
    }
    while (sizeof($string) != 0) {
        $img         = array_pop($string);
        $fileBigPath = "albums/$album/$album$recreated";
        echo "<li class='ui-state-default'><a href='#' onclick='details(" . $img . "); return false'><img src='$filePath$img'></li>";
    }

    ?>
</ul>
</div></div>
<script>
    function details(id) {
        alert(id);
        params = "id=" + encodeURIComponent(id);
        alert(params);
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        }
        else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                lBackground = document.createElement('div')
                lBackground.className = "lBackground";
                lBackground.setAttribute("id", "lBackground");
                lBox = document.createElement('div');
                lBox.className = "lBox";
                lBox.setAttribute("id", "lBox");
                lContents = "";
                lContents = xmlhttp.responseText;
                lBox.innerHTML = lContents;
                document.body.appendChild(lBox);
                document.body.appendChild(lBackground);
            }
        }
        xmlhttp.open("POST", "abc.php", true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.send(params);
    }
</script>

这是示例代码。

我想要的是,我希望将文件名作为参数发送

4

1 回答 1

1

将其更改为:

echo "<li class='ui-state-default'><a href='#' onclick='details(\"$img\"); return false'><img src='$filePath$img'></li>";

您在参数 to 周围缺少引号details()

于 2013-03-09T08:37:55.533 回答