Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从JSON格式发送数据;使用异步获取等待到PHP MySQL_Php_Mysql_Arrays_Json_Async Await - Fatal编程技术网

从JSON格式发送数据;使用异步获取等待到PHP MySQL

从JSON格式发送数据;使用异步获取等待到PHP MySQL,php,mysql,arrays,json,async-await,Php,Mysql,Arrays,Json,Async Await,几天以来,我一直试图解决这个问题。 需要什么: 1) 将数据从JSON(异步获取等待)发布到php 2) 接收数据并上传到我的服务器上 实际上,从现在起,我从PHP收到一个答案,但这个答案在我的console.log中是空的 请参阅下面的代码: 从JSON格式发送数据;使用异步获取等待到PHP MySQL 谢谢你的帮助,像往常一样,我继续寻找答案。这一个将被邮寄 表格 <form id="form"> <div id="areachatbox"></di

几天以来,我一直试图解决这个问题。 需要什么: 1) 将数据从JSON(异步获取等待)发布到php 2) 接收数据并上传到我的服务器上

实际上,从现在起,我从PHP收到一个答案,但这个答案在我的console.log中是空的

请参阅下面的代码:

从JSON格式发送数据;使用异步获取等待到PHP MySQL

谢谢你的帮助,像往常一样,我继续寻找答案。这一个将被邮寄

表格

  <form id="form">
    <div id="areachatbox"></div>
    <textarea type="text" id="message" name="message" ></textarea>
    <input id="submit" type="submit" value="Send">
  </form>

JSON:

        <script>
const form = document.getElementById('form');

 form.addEventListener('click', textarea);

     async function textarea(event) {
      event.preventDefault();

      const msg = document.getElementById('message').value;



      const response = await fetch('chatpost.php', {
        method: 'post',
        body:JSON.stringify({msg})
      })

      const data = await response.text();
      console.log(data);
    }

    </script>

const form=document.getElementById('form');
form.addEventListener(“单击”,文本区域);
异步函数textarea(事件){
event.preventDefault();
const msg=document.getElementById('message')。值;
const response=wait fetch('chatpost.php'{
方法:“post”,
正文:JSON.stringify({msg})
})
const data=wait response.text();
控制台日志(数据);
}
和PHP

<?php 

$json = json_decode(file_get_contents('http://localhost/XXXXXX/homepage.php'), true);

echo $json['msg'];

?> 

试试这个,让我知道:

$json=json_decode(file_get_contents('php://input'),true);