dimanche 26 mai 2019

Problem with deleting files in Laravel and jquery

I'm beginner with Laravel and JQuery.

I have this code:

<ul>
   <li class="file-id-46">- <a
      href="http://test.test/upload/other/1c186a1229c8c502c9bae2794b52a6f0.pdf"
      target="_blank">upload/other/1c186a1229c8c502c9bae2794b52a6f0.pdf</a>
      <a href="#" class="red removeThisFile"
         id="46">[delete file]</a>
   </li>
   <li class="file-id-47">- <a
      href="http://test.test/upload/other/65b13b47f09fc785d901e43e7864bab2.pdf"
      target="_blank">upload/other/65b13b47f09fc785d901e43e7864bab2.pdf</a>
      <a href="#" class="red removeThisFile"
         id="47">[delete file]</a>
   </li>
   <li class="file-id-48">- <a
      href="http://test.test/upload/other/19846324513791f79013fb8e5a7854d8.pdf"
      target="_blank">upload/other/19846324513791f79013fb8e5a7854d8.pdf</a>
      <a href="#" class="red removeThisFile"
         id="48">[delete file]</a>
   </li>
   <li class="file-id-49">- <a
      href="http://test.test/upload/other/fca69b7c02ae223cd167202368d3a555.pdf"
      target="_blank">upload/other/fca69b7c02ae223cd167202368d3a555.pdf</a>
      <a href="#" class="red removeThisFile"
         id="49">[delete file]</a>
   </li>
   <li class="file-id-50">- <a
      href="http://test.test/upload/other/2a1f88cd9f223a423a29594be3d8ce7a.pdf"
      target="_blank">upload/other/2a1f88cd9f223a423a29594be3d8ce7a.pdf</a>
      <a href="#" class="red removeThisFile"
         id="50">[delete file]</a>
   </li>
   <li class="file-id-51">- <a
      href="http://test.test/upload/other/dbe585a9716bd417437be6b0d5695a6a.pdf"
      target="_blank">upload/other/dbe585a9716bd417437be6b0d5695a6a.pdf</a>
      <a href="#" class="red removeThisFile"
         id="51">[delete file]</a>
   </li>
   <li class="file-id-52">- <a
      href="http://test.test/upload/other/585b8aa2cfd6a871eb3ed0e1c6d5e2b9.pdf"
      target="_blank">upload/other/585b8aa2cfd6a871eb3ed0e1c6d5e2b9.pdf</a>
      <a href="#" class="red removeThisFile"
         id="52">[delete file]</a>
   </li>
</ul>


$(".removeThisFile").click(function () {
                    var id = $(this).attr("id");
                    $('.file-id-' + id).hide();
                    $.ajax({
                        url: 'http://test.test/psCMS/removeOtherFile?id=52',
                        type: 'get',
                        dataType: 'json',
                        _token: $('meta[name="_token"]').attr('content'),
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                        },
                        cache: false,
                        success: function (response) {
                            $(this).hide();
                        }
                    });

Generally, jquery correctly sends a query to php (Laravel). The problem occurs in deleting files. The first file is deleted correctly. The next file can not be slept. I suspect that I have an invalid X-CSRF-TOKEN token after deleting the previous file.

How can I fix this problem?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2QlAcOw
via IFTTT

Aucun commentaire:

Enregistrer un commentaire