提取-发送POST数据 [英] Fetch - sending POST data

查看:63
本文介绍了提取-发送POST数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PHP脚本没有通过POST从提取接收任何信息.我在做什么错了?

My PHP script isn't receiving anything via POST from fetch. What am I doing wrong?

JavaScript:

Javascript:

fetch("http://127.0.0.1/script.php", {
    method: "post",
    body: "inputs=" + JSON.stringify({param: 7})
  }).then(response => response.json()).then(response => {
    console.log(response);
});

script.php:

script.php:

  echo "\nprinting POST:\n";
  print_r($_POST);

  echo "\nprinting GET:\n";
  print_r($_GET);
  die();

控制台:

打印POST:数组()

printing POST: Array ( )

打印GET:数组()

推荐答案

该特定测试PHP文件的htaccess文件有问题.我已经使用它将某些内容发布到主项目文件夹/PHP文件中,并且一切正常.

There was something wrong with the htaccess file for that particular test PHP file. I've used it for posting something to the main project folder/PHP files and it went ok.

这篇关于提取-发送POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆