Both my jQuery code and PHP code are in the same PHP file (not two separate files).
I want to POST jQuery Variable to the php code.
But it Shows some errors ("undefined index") when running the php file.
PHP file is as follows (test.php).
<?php
$country = $_POST['userCountry'];
$ip = $_POST['userIp'];
echo $country;
echo $ip;
?>
<html>
<head><title></title>
<script src = "jquery.min.js"></script>
<script>
$.getJSON("http://freegeoip.net/json/", function(data) {
var country = data.country_name;
var ip = data.ip;
$.ajax({
method:"POST",
url:"test.php",
data:{userCountry:country, userIp:ip}
});
});
</script>
</head>
<body></body>
</html>