PHP erhalten keine Postdaten, die vom JavaScript -Fetch gesendet werden

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: PHP erhalten keine Postdaten, die vom JavaScript -Fetch gesendet werden

by Anonymous » 28 Feb 2025, 05:20

Ich weiß, dass diese Frage schon einmal gestellt wurde, aber ich habe noch keine Antwort gesehen, die für mich funktioniert hat. < /p>
var response = await fetch('login.php', {
mode: 'cors',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});

await response.json().then(data => {
console.log(data);
});

< /code>
Verifizierte 'Daten' war nicht leer. Das Skript login.php gibt eine gültige JSON -Antwort zurück, die ich beim Senden von Daten mit dem AJAX von JQuery erfolgreich verwendet habe. Aber mit einfacher JS bekomme ich ein leeres $ _post -Array.$.ajax({
dataType: 'json',
url: 'login.php',
type: 'post',
data: data,
}).done(function(data){
console.log(data)
});
< /code>
Und das ist wirklich alles, was ich versuche zu tun, wechseln Sie von jQuery zu Vanille -JS. Ich sehe nicht, was ich hier fehlt.

Top