幾天以來,我試圖解決這個問題。需要什么:1)將數據從 JSON(異步獲取等待)發布到 php 2)接收數據并將其上傳到我的服務器實際上,從現在開始,我從我的 PHP 收到了一個答案,但是這個在我的 console.log 中是空的。請看下面的代碼:從 FORM 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>和PHP<?php $json = json_decode(file_get_contents('http://localhost/XXXXXX/homepage.php'), true);echo $json['msg'];?>
- 1 回答
- 0 關注
- 107 瀏覽
添加回答
舉報
0/150
提交
取消