【发布时间】:2020-01-20 09:53:22
【问题描述】:
在我的 JS 代码中,我在一个 html 页面上输入 3 个输入并将它们保存到本地存储中。然后我想将这些变量发送到 php 以便将它们保存到我的数据库中。无论我多么努力地尝试没有使用 ajax、jquery 等的教程,我都可以在我的 php 代码中成功地从 javascript 发布和回显变量。我看不出为什么我下面的代码没有回显变量,但事实并非如此。
完整代码:https://codeshare.io/ayvK9e
精确的 PHP 元素(现在只是尝试发送普通变量,因为它仍然无法正常工作”
PHP:
foreach($_POST as $post_var){
echo($post_var);
}
JS:
const xhr = new XMLHttpRequest();
xhr.onload = function(){
const serverResponse = document.getElementById("serverResponse");
serverResponse.innerHTML = this.responseText
};
xhr.open("POST", "eDBase.php");
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send("name=dominic&message=bumbaclaat");
【问题讨论】:
-
否则HTTP请求是否成功?您的浏览器的开发者工具对此有何看法?
-
我得到的唯一错误是随机语法错误,表示 eDBase.php.3 处存在意外标记“
-
可以给我eDbase.php的代码吗?
-
试试这个:codeshare.io/aJ4r1r
-
HTML 索引文件:codeshare.io/5Op3EP
标签: javascript php html sql ajax