繁体   English   中英

javascript将数据发布到php并从php打印

[英]javascript post data to php and print from php

每个人

嗨,大家好

如何使用纯 javascript ajax 将数据从 javascript 发送到 php 并在 php 中打印?

文件 test.php 并将数据从 test.php 中的 javascript 代码发送到 test.php 和 print_r($_POST['from input name or name of variable'])

我搜索了很多但找不到

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']);

}

?>

不起作用

我认为这会帮助你更具体地了解这个问题..

<script>
 function sayHello() {
   var v1 = "hello";
   var v2 = "everyone";
   window.location.href = "result.php?w1=" + v1 + "&w2=" + v2;
 }
</script>

结果.php

function sayHelloBack() {
   if (isset($_GET["w1"]) && isset($_GET["w2"])) {
     $hello = $_GET["w1"] . " " . $_GET["w2"];
     echo $hello;
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM