I try to post single data to php page using javascript but can't get it right.. here's the code i tried:
try.js:
$(document).ready(function(){
var data = 1;
$.post( "data.php", { test_data: data});
});
data.php:
<?php
$test_data = $_POST[test_data];
echo $test_data
?>
when I access file data.php it says "Use of undefined constant test_data" and "Undefined index: test_data"..why is that?? can someone tell me what is wrong in the code please??
$_POST['test_data'];instead of$_POST[test_data];. And, if you access try.php directly using your browser, the index is of course undefined as you didn't post any data to the script.