2013-03-09 43 views
-2

我想發送參數化函數中的數組值,但我不知道爲什麼我無法做到這一點。示例代碼是:功能不能發送數組值

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

這是示例代碼。

我想是的,我想文件名要

+2

您的代碼不完整..請重新發布! – 2013-03-09 08:22:55

+1

你關心縮進嗎? – 2013-03-09 08:24:22

+1

你的問題不清楚,代碼不清楚。 – bgusach 2013-03-09 08:26:55

回答

1

更改其發送的參數去:

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

你失蹤引號details()

+0

謝謝soooooooo多。我真的厭倦了這個問題。很高興它的工作 – user2034843 2013-03-09 08:39:49