Javascript:
fetch("https://localhost/data.php", {
method: "POST",
body: JSON.stringify({
data1: data1,
data2: data2
})
})
.then(res => res.json())
.then(json => function (json) {
console.log("Successful fetch.");
console.log(json);
})
.catch((error) => function (error) {
console.log("Failed to fetch. " + error);
});
数据.php:
<?php
echo '{
reply: true
}';
?>
我正在尝试使用带有 fetch 的 post 请求,但我无法从 PHP 文件中得到回复,但我可以从浏览器访问它。
错误在这一行
.then(json => function (json) {
fetch("https://localhost/data.php", {
method: "POST",
body: JSON.stringify({
data1: data1,
data2: data2
})
})
.then(res => res.json())
.then(json => {
console.log("Successful fetch.");
console.log(json);
})