2016-04-18 3 views
0

В текущем коде я получаю имя файла при загрузке файла. После загрузки я взорву имя файла и ответ, который я получаю, приводится ниже. Моя проблема в том, как можно получить данные в jQuery и добавить с помощью html?Как добавить данные ответа?

В ответе на предупреждение jQuery отображается " Localization,dummy " Как можно добавить эти два данных отдельно.

консоли: Ответ

{"success":true,"exploded_filename":["Localization","dummy"],"id":"2"} 

консоли: Json

success    true 
exploded_filename ["Localization", "dummy"] 
0     "Localization" 
1     "dummy" 
id     "2" 

Jquery в Dropzone

Dropzone.options.myDropzone = { 
      // Prevents Dropzone from uploading dropped files immediately 
      autoProcessQueue: true, 
      parallelUploads: 20, 
      uploadMultiple: true, 
      maxFilesize: 10, 
      maxFiles: 20, 
      init: function() { 
       myDropzone = this; // closure 
       // You might want to show the submit button only when 
       // files are dropped here: 
       this.on("success", function(file, responseText) { 
        myDropzone.removeFile(file); 
        if(responseText.success == true){ 
         $(".createProcessEntriesFileUpload").show(); 
         $("#my-dropzone").hide(); 
         $("#filenameFormGroup").show(); 
         $(".createProcessEntriesMessage").hide(); 
         alert(responseText.exploded_filename); 
         $("#filename").append('<a class="btn btn-sm btn-default download" href="" data-file="">'+responseText.exploded_filename+'</a> <a href="" class="removeProcessEntryFile" style="color: #333; cursor: pointer;"><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Add file detail</button></a><br>'); 

         /*setTimeout(function() { 
         location.href = '<?php echo url("/");?>/customers/list/process/<?php echo $id;?>/entries'; 
         }, 3000);*/ 
        }; 
       }); 
      } 
     }; 

контроллер Page

public function storeFile(ProcessEntriesRequest $request, $id) 
    { 
     $files      = $request->file('file'); 
     foreach($files as $file){ 
      $orginalName   = $file->getClientOriginalName(); 
      $split_file   = explode('.', $orginalName); 
      $exploded_filename[] = $split_file[0]; 
      $extension    = $file->getClientOriginalExtension(); 
      $filename    = str_random(10); 
      Storage::disk('local')->makeDirectory($request->entryID, 0777); 
      Storage::disk('local')->put($request->entryID.'/'.$filename.'.'.$extension, File::get($file)); 
     } 

     return response()->json(['success' => true, 'exploded_filename' => $exploded_filename, 'id' => $id]); 
    } 
+0

Должно быть 'responseText.exploded_filename [0]' – rmondesilva

+0

@rmondesilva Если я использую «responseText.exploded_filename [0]», результат получает «L». Потому что ответ «Локализация, pdf». – Rahul

ответ

0

Использование join

console.log(responseText.exploded_filename.join(',')); 
$("#filename").append('<a class="btn btn-sm btn-default download" href="" data-file="">'+responseText.exploded_filename.join('.')+'</a> <a href="" class="removeProcessEntryFile" style="color: #333; cursor: pointer;"><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Add file detail</button></a><br>'); 

или Используйте цикл

var totalfiles = '<ul>'; 
$.each(responseText.exploded_filename,function(i,v){ 
    totalfiles+='<li><a class="btn btn-sm btn-default download" href="" data-file="">'+v+'</a></li>'; 
}); 
totalfiles+='</ul>' 

$("#filename").append(totalfiles+'<a href="" class="removeProcessEntryFile" style="color: #333; cursor: pointer;"><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Add file detail</button></a><br>'); 
+0

Я не понял. Не могли бы вы объяснить? – Rahul

+0

@ Рахул, что именно вы не получили? – madalinivascu

+0

Локализация и PDF - это два имени файла. В моем вопросе я поместил другое имя файла для pdf. – Rahul

0

Madalin правильно, вы должны использовать метод join. Если у вас есть массив data = ['Localization', 'pdf'], то data.join('.') вернет 'Localization.pdf'. See the doc here.

+0

pdf - это имя файла. Это не расширение Я обновил свой вопрос – Rahul

Смежные вопросы