【问题标题】:Can't send array value in function [closed]无法在函数中发送数组值[关闭]
【发布时间】:2013-03-09 08:21:29
【问题描述】:

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

<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>

这是示例代码。

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

【问题讨论】:

  • 您的代码不完整..请重新发布!
  • 你关心缩进吗?
  • 你的问题不清楚,代码不清楚。

标签: php javascript arrays function params


【解决方案1】:

改成:

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

details() 的参数周围缺少引号。

【讨论】:

  • 非常感谢。我真的厌倦了这个问题。很高兴它成功了
猜你喜欢
  • 2019-07-14
  • 1970-01-01
  • 1970-01-01
  • 2015-02-13
  • 1970-01-01
  • 2014-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多