Home:ALL Converter>javascript post data to php and print from php

javascript post data to php and print from php

Ask Time:2019-12-03T07:51:35         Author:essencode

Json Formatter

everyone

Hi, everyone

how can i send data from javascript to php and print in php using pure javascript ajax?

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

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

Author:essencode,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/59148338/javascript-post-data-to-php-and-print-from-php
yy