Hello,
j'ai une application Laravel dans laquelle j'ai des appels ajax (via des boutons). Quand j'utilise les liens url directement dans un navigateur ainsi que via ajax, tout marche parfaitement.
J'ai entrepris de porter l'application sur du httpS, du coups, tous marche, sauf les appels ajax j'ai une server error 500 (les liens mis dans le navigateurs directement marchent par contre parfaitement).
Le code minimaliste qui reproduit le problème est le suivant:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 $("#refreshmsglist").click(function(e) { $('#btngetmessages > i ').addClass('spinner'); $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': '<?php echo csrf_token(); ?>' } }); $.ajax({ method: 'GET', url: '/trackers/{{ $tracker->id }}/messages', data: {}, // a JSON object to send back success: function(response){ console.log(response); document.location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { console.log(JSON.stringify(jqXHR)); console.log("AJAX error: " + textStatus + ' : ' + errorThrown); $('#btngetmessages > i ').removeClass('spinner'); }, complete: function () { $('#btngetmessages > i ').removeClass('spinner'); } }); });
Quand reprend l'URL appelée avec le nom de domaine https://www.mywebsite.com/trackers/56/messages l'appel marche bien. via Ajax, j'ai
Est ce qu'il y a des options particulières à rajouter aux headers (en plus du X-CSRF-TOKEN) pour que cela marche?Citation:
Request URL: https://www.mywebsite.com/trackers/57/messages
Request Method: GET
Status Code: 500
Remote Address: 109.234.164.13:443
Referrer Policy: no-referrer-when-downgrade
Vu que j'utilise l'authentification Auth() proposée de base par Laravel j'ai rajouté
mais cela ne change rienCode:
1
2
3 xhrFields: { withCredentials: true },