简体   繁体   English

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

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

everyone每个人

Hi, everyone嗨,大家好

how can i send data from javascript to php and print in php using pure javascript ajax?如何使用纯 javascript ajax 将数据从 javascript 发送到 php 并在 php 中打印?

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

I searched a lot but couldn't find it我搜索了很多但找不到

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

}

?>

dosen't work不起作用

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结果.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