Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript][PHP]Problem z kasowaniem plików w Laravel i jquery
northwest
post 26.05.2019, 14:07:27
Post #1





Grupa: Zarejestrowani
Postów: 788
Pomógł: 1
Dołączył: 17.09.2004

Ostrzeżenie: (10%)
X----


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?
Go to the top of the page
+Quote Post
markonix
post 26.05.2019, 18:28:03
Post #2





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

Ostrzeżenie: (0%)
-----


Debugować.


--------------------
Go to the top of the page
+Quote Post
trueblue
post 26.05.2019, 18:36:49
Post #3





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Wygeneruj podczas usuwania nowy token, zwróć wraz z odpowiedzią i wstaw do <meta>.


--------------------
Go to the top of the page
+Quote Post
markonix
post 26.05.2019, 23:26:54
Post #4





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

Ostrzeżenie: (0%)
-----


Cytat(trueblue @ 26.05.2019, 19:36:49 ) *
Wygeneruj podczas usuwania nowy token, zwróć wraz z odpowiedzią i wstaw do <meta>.

Niby po co?


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 28.03.2024 - 10:08