2016-04-19 4 views
0

削除ボタンをクリックするとこのエラーが発生します。 SyntaxError:JSON.parse:JSONデータの第1行第1列の予期しないデータ終了。それを解決するためのあらゆる努力が無駄であると証明されたので、誰かがそれを解決するのを助けることができますか?ブートストラップファイルインプットプラグインjsonエラー

ここにエラーのスクリーンショットがあります。

json error

そして、ここで私のディレクトリ構造のスクリーンショットです。 directory structure

は、ここでは、コード

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="UTF-8"/> 
    <title>Bootstrap File Upload</title> 

    <link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"> 
    <link href="css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" /> 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 
    <script src="js/fileinput.min.js" type="text/javascript"></script> 
    <script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js" type="text/javascript"></script> 

    </head> 

    <body> 



    <input id="files" name="images[]" type="file" multiple=true class="file-loading"> 
    </body> 
    <?php 
    $directory = "images_/";  
    $images = glob($directory . "*.*"); 
    ?> 

    <script> 
    $("#files").fileinput({ 
    uploadUrl: "upload.php", 
    uploadAsync: false, 
    minFileCount: 1, 
    maxFileCount: 20, 
    showUpload: false, 
    showRemove: false, 
    initialPreview: [ 
    <?php foreach($images as $image){?> 
     "<img src='<?php echo $image; ?>' height='120px' class='file-preview-image'>", 
    <?php } ?>], 
    initialPreviewConfig: [<?php foreach($images as $image){ $infoImages=explode("/",$image);?> 
    {caption: "<?php echo $infoImages[1];?>", height: "120px", url: "delete.php", key:"<?php echo $infoImages[1];?>"}, 
    <?php } ?>] 
    }).on("filebatchselected", function(event, files) { 

    $("#files").fileinput("upload"); 

    }); 

    </script> 
</html> 

はここ

<?php 
$enclosedFolder="images_/"; 
// Count sent by plugin 
$Images =count(isset($_FILES['images']['name'])?$_FILES['images']['name']:0); 
$infoImagesUploaded = array(); 
for($i = 0; $i < $Images; $i++) { 
    // The name and the temporary file name we're gonna attach 
    $nameFile=isset($_FILES['images']['name'][$i])?$_FILES['images']['name'][$i]:null; 
    $nameTemp=isset($_FILES['images']['tmp_name'][$i])?$_FILES['images']['tmp_name'][$i]:null; 

    $pathFile=$enclosedFolder.$nameFile; 

    move_uploaded_file($nameTemp,$pathFile); 

    $infoImagesUploaded[$i]=array("caption"=>"$nameFile","height"=>"120px","url"=>"delete.php","key"=>$nameFile); 
    $ImagesUploaded[$i]="<img height='120px' src='$pathFile' class='file-preview-image'>"; 
    } 
$arr = array("file_id"=>0,"overwriteInitial"=>true,"initialPreviewConfig"=>$infoImagesUploaded, 
      "initialPreview"=>$ImagesUploaded); 
echo json_encode($arr); 
?> 

私のupload.phpだだし、ここにGithubに見られるように、私のdelete.phpは

<?php 
$enclosedFolder="images_/"; 
if($_SERVER['REQUEST_METHOD']=="DELETE"){ 
      parse_str(file_get_contents("php://input"),$dataDELETE); 
      $key= $dataDELETE['key']; 
      unlink($enclosedFolder.$key); 

      echo 0; 
} 
?> 

答えて

0

です:

Its an error on your server code returning an invalid json format for your upload response. Debug it with firebug or javascript console and resolve to return a right JSON format. You must return a RIGHT JSON response from your AJAX (even if you do not have anything... you must at least return an empty JSON object like {}).

+0

これはコード全体です。私はどこにエラーがあるのか​​分かりません。できますか? –

+0

fileinput関数に送信するJSONデータ。 – Matheno