ajax从文件夹调试中获取图像

时间:2015-09-26 10:55:53

标签: ajax

  function ajax_json(folder){
      var thumbnailbox = $('#thumbnailbox');
      $.ajax({
        url:"json_data.php",
        dataType:"json",
        type:"POST",
        data: {folder: JSON.stringify(folder)},
        contentType: "application/json; charset=utf-8",
        success:function(d){
          var temp = '';
            for (var o in d) {
                 if (d.hasOwnProperty(o) && d[o].hasOwnProperty('src') && d[o].src !== '') {
                     //create image
                     temp += "<div class='typebox'><img id='typeImg' src=" + d[o].src + "></div>";
                 }
            }
          }, error: function (jqXHR, textStatus, errorThrown){
            console.log("textStatus = " + textStatus + "\terrorThrown = " + errorThrown);
            alert(XMLHttpRequest.status);
            alert(XMLHttpRequest.readyState);
            alert(textStatus);
        }
      });
    }

PHP

<?php
header("Content-Type: application/json");
$folder = $_POST["folder"];
$jsonData = '{';
$dir = $folder."/";
$dirHandle = opendir($dir); 
$i = 0;
while ($file = readdir($dirHandle)) {
    if(!is_dir($file) && preg_match("/.jpg|.gif|.png/i", $file)){
        $i++;
        $src = "$dir$file";
$jsonData .= '"img'.$i.'":{ "num":"'.$i.'","src":"'.$src.'", "name":"'.$file.'" },';
    }
}
closedir($dirHandle);
$jsonData = chop($jsonData, ",");
$jsonData .= '}';
echo $jsonData;
?>

错误

textStatus = parsererror    errorThrown = SyntaxError: Unexpected token <

我的意图是使用ajax从我的文件夹中获取图像,它有错误,我无法找到我错过的错误,有人可以帮我看看吗?我无法调试它。

0 个答案:

没有答案
相关问题