javascript - javascript 将数据发布到 php 并从 php 打印
问题描述
每个人
大家好
如何使用纯 javascript ajax 将数据从 javascript 发送到 php 并在 php 中打印?
文件 test.php 并将数据从 test.php 中的 javascript 代码发送到 test.php 和 print_r($_POST['来自输入名称或变量名称'])
我搜索了很多但找不到
code
<script>
//file test.php
var HTTP=new XMLHttpRequest();
var params={name:"jack",family:"jackers",age:"30"};
HTTP.open("POST","http://127.0.0.1/test/test.php");
HTTP.send(params);
</script>
<?php
//file test.php
if (isset($_POST['name'])){
print_r($_POST['name']."<br>");
print_r($_POST['family']."<br>");
print_r($_POST['age']);
}
?>
不工作
解决方案
I think this would help you to get more specific regarding the question..
<script>
function sayHello() {
var v1 = "hello";
var v2 = "everyone";
window.location.href = "result.php?w1=" + v1 + "&w2=" + v2;
}
</script>
result.php
function sayHelloBack() {
if (isset($_GET["w1"]) && isset($_GET["w2"])) {
$hello = $_GET["w1"] . " " . $_GET["w2"];
echo $hello;
}
}
推荐阅读
- php - 如何在 PHP 中使用 getenv?
- javascript - TypeError:无法读取未定义 onFormSubmit 的属性“响应”
- selenium - 无法使用 sendkeys 在文本字段中发送数据
- powerbi - Vlookup 到另一个表的 DAX 公式
- python - 在 python 中处理复数
- terraform - 需要一种方法来获取 Consul 的 retry_join 的所有私有 IP,而无需在配置文件中对其进行硬编码
- python-3.x - 关闭 Imgui 窗口:这看起来应该很容易。如何做到这一点?
- oracle - Oracle SQL Loader 控制文件忽略省略号
- javascript - 使用现有画布而不丢失 pIxi.js 中的内容
- python - 在 Google Colab 中成功运行预训练的 LDA-Mallet 模型并推断未见文档的主题