Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript][PHP]Problem z kasowaniem plików w Laravel i jquery
Forum PHP.pl > Forum > Przedszkole
northwest
Witajcie,
Mam taki kod:

  1.  
  2. <ul>
  3. <li class="file-id-46">- <a
  4. href="http://test.test/upload/other/1c186a1229c8c502c9bae2794b52a6f0.pdf"
  5. target="_blank">upload/other/1c186a1229c8c502c9bae2794b52a6f0.pdf</a>
  6. <a href="#" class="red removeThisFile"
  7. id="46">[delete file]</a>
  8. </li>
  9. <li class="file-id-47">- <a
  10. href="http://test.test/upload/other/65b13b47f09fc785d901e43e7864bab2.pdf"
  11. target="_blank">upload/other/65b13b47f09fc785d901e43e7864bab2.pdf</a>
  12. <a href="#" class="red removeThisFile"
  13. id="47">[delete file]</a>
  14. </li>
  15. <li class="file-id-48">- <a
  16. href="http://test.test/upload/other/19846324513791f79013fb8e5a7854d8.pdf"
  17. target="_blank">upload/other/19846324513791f79013fb8e5a7854d8.pdf</a>
  18. <a href="#" class="red removeThisFile"
  19. id="48">[delete file]</a>
  20. </li>
  21. <li class="file-id-49">- <a
  22. href="http://test.test/upload/other/fca69b7c02ae223cd167202368d3a555.pdf"
  23. target="_blank">upload/other/fca69b7c02ae223cd167202368d3a555.pdf</a>
  24. <a href="#" class="red removeThisFile"
  25. id="49">[delete file]</a>
  26. </li>
  27. <li class="file-id-50">- <a
  28. href="http://test.test/upload/other/2a1f88cd9f223a423a29594be3d8ce7a.pdf"
  29. target="_blank">upload/other/2a1f88cd9f223a423a29594be3d8ce7a.pdf</a>
  30. <a href="#" class="red removeThisFile"
  31. id="50">[delete file]</a>
  32. </li>
  33. <li class="file-id-51">- <a
  34. href="http://test.test/upload/other/dbe585a9716bd417437be6b0d5695a6a.pdf"
  35. target="_blank">upload/other/dbe585a9716bd417437be6b0d5695a6a.pdf</a>
  36. <a href="#" class="red removeThisFile"
  37. id="51">[delete file]</a>
  38. </li>
  39. <li class="file-id-52">- <a
  40. href="http://test.test/upload/other/585b8aa2cfd6a871eb3ed0e1c6d5e2b9.pdf"
  41. target="_blank">upload/other/585b8aa2cfd6a871eb3ed0e1c6d5e2b9.pdf</a>
  42. <a href="#" class="red removeThisFile"
  43. id="52">[delete file]</a>
  44. </li>
  45. </ul>
  46.  
  47.  
  48. $(".removeThisFile").click(function () {
  49. var id = $(this).attr("id");
  50. $('.file-id-' + id).hide();
  51. $.ajax({
  52. url: 'http://test.test/psCMS/removeOtherFile?id=52',
  53. type: 'get',
  54. dataType: 'json',
  55. _token: $('meta[name="_token"]').attr('content'),
  56. headers: {
  57. 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
  58. },
  59. cache: false,
  60. success: function (response) {
  61. $(this).hide();
  62. }
  63. });
  64.  
  65.  


Generalnie jquery poprawnie wysyła zapytanie do php (Laravel).
Problem występuje w kasowaniu plików. Pierwszy plik zostaje usunięty poprawnie. Usnięcie kolejnego pliki nie udaje się.
Podejrzewam iż mam nieważny token X-CSRF-TOKEN po usunięciu poprzedniego pliku.

W jaki sposób mogę naprawić ten problem?
markonix
Debugować.
trueblue
Wygeneruj podczas usuwania nowy token, zwróć wraz z odpowiedzią i wstaw do <meta>.
markonix
Cytat(trueblue @ 26.05.2019, 19:36:49 ) *
Wygeneruj podczas usuwania nowy token, zwróć wraz z odpowiedzią i wstaw do <meta>.

Niby po co?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.